Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Database query 1

Status
Not open for further replies.

simoncpage

Programmer
Apr 4, 2002
256
GB
Does anyone know of any examples I can look at for querying access databases from an excel userform (i.e without using the activesheet at all)?

Any help on this would be great! :)

Simon

 
Have a look in the help files for ADO - shouldn't matter where you are - just set a reference to Access and Bob's your mother's brother
HTH
Geoff
 
Xlbo I have already looked through there all I can find is querying on to the worksheet. The problem is that I want the destination property (when using QueryTables) to be a text box on a userform not a worsheet range. Do you know of any specific examples that I can look at where result are displayed on a userform?

Thanks
 
Found this on an excel forum archive - not quite what you want (it goes to a combobox) but should get you started:
Sub ADOFrmSetup()
Dim cn As New ADODB.Connection
Dim Rs As New ADODB.Recordset

cn.ConnectionString = "L:\Public\Personnel\emp.mdb"
cn.Open
Rs.Open "SELECT * FROM EMPLOYEES", cn, CursorType:=adOpenStatic,
LockType:=adLockReadOnly

Frm.ComboBox1.Clear
Do While Not Rs.EOF
Frm.ComboBox1.AddItem Rs.Fields("Empcode")
Rs.MoveNext
Loop
Rs.Close
cn.Close
Set RS = Nothing
Frm.Show
End Sub

This populates a combobox with the results of a SQL string query in Access - If you're gonna populate a textbox, you'll only get one record so you don't need to do any of the Do while not Rs.EOF
should just need Frm.Textbox1.value = Rs.Fields("FieldName")

HTH
Geoff
 
I still can't manage to get the desired effect - anyone got any examples that I could play with???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top