Query based on combo box selection

coryt

Registered User.
Local time
Today, 05:19
Joined
Jun 13, 2003
Messages
82
I have a form with a combo box that lists all the tables that are in a seperate database. I would like the user to be able to choose the table name from the cboBox, click "OK" and have a select query open and show all information pertaining to the selected table. The trick is, as I stated before, is the table that the information is being drawn from is located in a seperate database.

I guess my question is:

Is there a way for me to set the SQL behind the query to automatically change with the users selection.

Thanks in advance.
 
you need to create a querydef object and supply the query itself "on the fly". use VBA
 
Thanks FoFa

I figured it out yesterday.

Incase you were wondering, I just made a new form and placed a text box for each column that is in the tables. Then I set up the code like this:

Private Sub Form_Load()
Me.RecordSource = "SELECT ColumnNames FROM " & [Forms]![FormName].[ComboBoxName] & " IN 'Path to DB';"
End Sub

I also set the form to open in the datasheet view.

I works great.
 

Users who are viewing this thread

Back
Top Bottom