We help IT Professionals succeed at work.

Populate Access Combo Box from SQL Query

Ant_Dogg
Ant_Dogg asked
on
I'm trying to do the following:

Enter your name
Enter you password
[submit]

After submission with button and authentication, populate the appropriate data based off a query on the person's name into a combo box. Any thoughts on how to do this?  I'm writing the function/macros with VB through Access.

I'll usually do something like this:

Dim rselect As New ADODB.Recordset
' open connection stuff here
rselect.Open "select data where name = name", cnn, adOpenStatic, adLockOptimistic

Can I push this rselect set into the combo box or is there a better way to do it?

Comment
Watch Question

BRONZE EXPERT

Commented:
Can you clarify what you are using for your forms and  code.

Are you writing a VB front-end with an Access backend or do you mean you are writing vba code in an Access front-end (also with an Access backend)

Author

Commented:
It's Access forms with a SQL server backend.  The behavior of all my buttons are controlled with VB code through Access, such as connection, submissions, and updates to the database.

I want this button to query the SQL database, return a recordset (1 column) and populate it to a combo box.
BRONZE EXPERT
Commented:
You just set the rowsource of the combo to the sql string that you are currently using for your recordset.
Forms!formname!comboname.rowsource = strSQL

I'm assuming your real sql is correctly structured, as the code you posted is not.

Author

Commented:
Thats what I was looking for, thanks!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.