View Full Version : Changing data source of a form


s.booth
02-07-2002, 12:21 AM
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

Emohawk
02-07-2002, 01:20 AM
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.