Change source table/qry at run time

varunmathur

Registered User.
Local time
Today, 04:31
Joined
Feb 3, 2001
Messages
68
Hi
I am using a no of forms/Reports containing the same fields and design to output/obtain data from different queries depending upon the users choice.
Is there a way by which I can change the source of the form/Report at runtime depending on the users to choice to obtain data through a different query.
Thanking you in anticipation
varun
 
For example:

Code:
Private Sub ChangeRecordSource()


On Error GoTo Err_ChangeRecordSource

'Purpose: Change the form's Recordsource
Dim bWasFilterOn As Boolean


'Save the FilterOn state. (It's lost during RecordSource change.)
bWasFilterOn = Me.FilterOn


'Change the RecordSource
If Me.RecordSource <> "tblForms" Then
Me.RecordSource = "tblForms"
End If


'Apply the filter again, if it was on
If bWasFilterOn And Not Me.FilterOn Then
Me.FilterOn = True
End If


Exit_ChangeRecordSource:
Exit Sub


Err_ChangeRecordSource:
MsgBox Err.Number & ": " & Err.Description, vbInformation, Me.Module.Name & "~ChangeRecordSource"
Resume Exit_ChangeRecordSource


End Sub

Alex
 

Users who are viewing this thread

Back
Top Bottom