Use of OpenArgs

C

chris

I am opening a form called frmFindPerson from a form called
frmEditPerProj. I am passing the form name of the first form to the
second form by placeing it in openArgs in doCmd.OpenForm as
"frmEditPerProj".

I want to select a record from the second form and pass a field value
back to the first using the form name passed in OpenArgs to define the
field to be filled with this data. I was not sure whether I could use
OpenArgs dircetly so I have set up a variable and assigned the value
of OpenArgs to it as follows

Private Sub cmdSelect_Click()
Dim strFormName As String
strFormName = Forms!frmfindPerson.OpenArgs

In order to check that the variable contains the form name I added the
following which does confirm this

MsgBox ("OpenArgs is " & strFormName)

I then want to use this value to fill a field on the first form with
data from the second. I have tried using the following and various
variations on it with and without brackets/quotes etc but nothing
works

Forms![strFormName]!PersonID.Value = Me!PersonID

If however if I put the name of the first form (frmEditPerProj) into
the line instead of strFormName it does work.

What am I doing wrong? I want to do this using openArgs as I want to
use the form frmFindPerson, for many different situations and this
seemed a good way of using generic code to suit all these situations.
Perhaps someone can suggest another solution if I am barking up the
wrong tree.

Chris
 
A

Arvin Meyer [MVP]

Pass the string as the last argument in the OpenForm statement.

In the opened form's Open event, use it like:

Me.txtWhatever = OpenArgs

Think of OpenArgs as a special global variable that can be used to pass a
string from one form to another. You can have more than 1 value in the
string and parse it out in the newly opened form. You can also convert a
string to another, more apppropriate, datatype.
 
C

chris

Yes, I'm passing it to the second form in the correct way. The problem
is trying to use it as the form name for setting a field value back on
the first form something like this. I presume that OpenArgs is string
data type when it is received by the opened form. What type is
required when it is used in the way I am trying to do below?

Forms.[Me.OpenArgs].PersonID.Value = Me!PersonID

ie. value of PersonID on the first form = value of PersonID on the
second form

Chris
 
A

Arvin Meyer [MVP]

It doesn't work like that, but once PersonID is set on the second form, you
can use:

Me.PersonID = Forms!NameOfSecondForm!PersonID
 
D

Douglas J. Steele

Assuming that OpenArgs contains the name of the form on which you're trying
to change the value, try:

Forms(Me.OpenArgs)!PersonID.Value = Me!PersonID
 

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