Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Link Excel form to Access query result or any other ADO

Is it possible to have the rowsource of a list box in a form be the result of
an access query.
Same question regarding a TextBox.

Many thanks,
Dan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Link Excel form to Access query result or any other ADO

this will work for combobox
Private Sub UserForm_Initialize()

On Error GoTo UserForm_Initialize_Err
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Path\to mydatabase\mydatabase.mdb"

rst.Open "SELECT DISTINCT table.field" _
& "FROM table;", _
cnn, adOpenStatic
rst.MoveFirst

With Me.ComboBox1
.Clear
Do
.AddItem rst!Field
rst.MoveNext
Loop Until rst.EOF
End With

UserForm_Initialize_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub

UserForm_Initialize_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume UserForm_Initialize_Exit
End Sub


"Dan" wrote:

Is it possible to have the rowsource of a list box in a form be the result of
an access query.
Same question regarding a TextBox.

Many thanks,
Dan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Link Excel form to Access query result or any other ADO

I was trying to create a macro that went to several workbooks then to
a specific worksheet did an autofilter on a specific field the copied
and pasted those into a new work book. The paste of the selection
will be dynamic. I can give a specific cell destination for the paste
in a new work book. Do you have a macro that does something similar
in which I could tweak the code??

If you do I will be up a little while.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel link to access query not working richard Excel Discussion (Misc queries) 0 February 19th 09 06:11 AM
Link form to Access query result Dan Excel Programming 3 June 21st 07 10:07 PM
Importing result from Access query to Excel but the result only c. Edwin Excel Discussion (Misc queries) 0 March 16th 06 01:36 AM
Import query from access to excel, link to template, email on jwr Links and Linking in Excel 11 October 15th 05 05:25 PM
Link Access query to refresh an EXCEL file Dancer4u New Users to Excel 1 January 13th 05 05:24 PM


All times are GMT +1. The time now is 09:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"