Passing parameters between forms in MS Access
DoCmd.OpenForm
allows you to pass an arbitrary value as the last parameter. This value can be accessed in the new form as Me.OpenArgs
:
' Invoked by some Button on the first form 'Sub GoToSecondPage() DoCmd.OpenForm "MySecondPage", acNormal, , , , , txtEmployee.ValueEnd Sub' Second form 'Sub Form_Open(Cancel As Integer) If Not IsNull(Me.OpenArgs) Then lblShowEmployeeName.Value = Me.OpenArgs End IfEnd Sub
(Code example untested.)
You can pass a delimited string as the OpenArgs parameter:
DoCmd.OpenForm FormName:="miscForm", OpenArgs:=paramstring
Here's a routine for processing a pipe-delimited string passed as the parameter to DoCmd.OpenForm:
Dim Pstring As VariantIf Len(Me.OpenArgs) > 0 Then Pstring = Split(Me.OpenArgs, "|") var1 = Pstring(0) <etc..>End If
Personally I would pass them through the open arguments when opening the form. For example from form A your would write
DoCmd.OpenForm "frmB", , , , , acDialog,”Badger”
And then in the OnOpen event of form B you can capture what you have sent like this
Me.txtSomething=Me.OpenArgs
You can only pass one thing however What I do a lot is pass a pipe delimited string in the open arguments and then split that out.