Dynamically assigning RecordSource

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear All,

I want to dynamically assign RecordSource to my acces form. I have a main
form which has 2 buttons on it. Depending on which button is clicked . the
recordsource should be dynamically assigned.

For example if I click Button1 a new form should open and its should assign
a Recordsource "btn1RecordSource"

and if Button2 is clicked it should assign a different record source lets say
"btn2RecordSource" to the same form.

So its 1 form but different record sources.

Any help would be greatly appreciated.

cheers,
Sam Solomon
 
Sam,

Use the OpenArgs parameter of the OpenForm method to pass the name of your
RecordSource, then assign it in the OnOpen event procedure of the 2nd form:

' Typical command button code on first form
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "YourQueryAsOpenArgs"

' 2nd form OnOpen event procedure code
If Not IsNull(Me.OpenArgs) Then
Me.RecordSource = Me.OpenArgs
End If

Sprinks
 
Back
Top