Run FormB form FormA and pass parameters

J

jsccorps

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).
 
P

Pat Hartman\(MVP\)

The button wizard will build the necessary code for you. You can then
modify it and add your parameters as the OpenArgs argument.
 
K

Klatuu

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)
 
P

Pat Hartman\(MVP\)

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top