Run FormB form FormA and pass parameters

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

Guest

From a currently open FormA, I want to 1) open another FormB, 2) Pass it
parameters used in FormA (e.g. Manager# and SalesDate), and 3) automatically
run FormB (FormB never appears on the screen).
 
The button wizard will build the necessary code for you. You can then
modify it and add your parameters as the OpenArgs argument.
 
Pat's answer is correct, but probably needs some clarification. First, to
pass parameters to another form, you use the OpenArgs argument of the
OpenForm method. It allows a string value to be passed. So, in your case
where you want to pass two values, you will need to use some formatting or
indicator so FormB will be able to parse the two values. Also, assigning
values in the receiving form (FormB) must be done in the Open event. The
example below uses the Split function in FormB to separate manager from
SalesDate.

In FormA

strParms = Me.Manager & "|" & Cstr(Me.SalesDate)
DoCmd.OpenForm "FormB", , , , , , strParms

In FormB (Open event)

If Not IsNUll(Me.OpenArgs) Then
varParms = Split(Me.OpenArgs, "|")
End If

Me.Manager = varParms(0)
Me.SaleDate = varParms(1)
 
Thank you. It was past my bedtime.
Klatuu said:
Pat's answer is correct, but probably needs some clarification. First, to
pass parameters to another form, you use the OpenArgs argument of the
OpenForm method. It allows a string value to be passed. So, in your case
where you want to pass two values, you will need to use some formatting or
indicator so FormB will be able to parse the two values. Also, assigning
values in the receiving form (FormB) must be done in the Open event. The
example below uses the Split function in FormB to separate manager from
SalesDate.

In FormA

strParms = Me.Manager & "|" & Cstr(Me.SalesDate)
DoCmd.OpenForm "FormB", , , , , , strParms

In FormB (Open event)

If Not IsNUll(Me.OpenArgs) Then
varParms = Split(Me.OpenArgs, "|")
End If

Me.Manager = varParms(0)
Me.SaleDate = varParms(1)
 
Back
Top