Changing data source of a form

s.booth

Registered User.
Local time
Today, 21:11
Joined
Feb 5, 2002
Messages
23
Is it possible to change the data source of a form by the clicking a button on the form.

ie. have 2 querries that show differnt ranges of records that can be switched between while the form is still open
 
Assuming that the bound controls are all going to be link to the same fields on both queries this works.

Create your two queries as per normal and set the default query as the record source of the form via the properties.

Add your button that toggles between the two queries and insert this code.

Sub Toggle_Query_Button_Click()
If Me.RecordSource = "Query1" Then
Me.RecordSource = "Query2"
Else
Me.RecordSource = "Query1"
End If
Me.Refresh
End Sub

Where "Query1" and "Query2" are, insert the names of your relevant query.

Hope this makes sense.
 

Users who are viewing this thread

Back
Top Bottom