Recordsouce question

G

golfinray

Can I change the recordsource of a form on the fly? In other words, I have
one table (a small one-to-one so I didn't split it) and I would like to have
3 maybe 4 queries off that one table. Then change the recordsouce of the form
to query1, or query 2, etc, depending on what the user picks in a combo. The
fields displayed on the form from each query would be the same. I know I
might be able to do it with case statements, but is there an easier way?
Thanks a bunch!!!
 
D

Dirk Goldgar

golfinray said:
Can I change the recordsource of a form on the fly?
Yes.

In other words, I have
one table (a small one-to-one so I didn't split it) and I would like to
have
3 maybe 4 queries off that one table. Then change the recordsouce of the
form
to query1, or query 2, etc, depending on what the user picks in a combo.
The
fields displayed on the form from each query would be the same. I know I
might be able to do it with case statements, but is there an easier way?

You could set up your combo with two columns, one containing the display
text for the user to pick, and the other containing the SQL statement (or
query/table name) to be assigned to the form's RecordSource. Code in the
combo's AfterUpdate event might look like this:

'----- start of example code ------
Private Sub cboDataSource_AfterUpdate()

Me.RecordSource = _
Me.cboDataSource.Column(1) & vbNullString

End Sub
'----- end of example code ------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top