Passing form name to another form...

E

EyeTech

I have a need to pass a form name from one form to another in which the
original forms name will be used by the second form to populate a field on
the original after a search is done. I have been successful in passing the
form name in the OpenArgs parameter for the called form, but I have not been
able to use the arg or any other variable I might place the name in to
reference the original form.

If I pass "Form_A" in OpenArgs, I can confirm that it is succesfully passed
to Form_B, however, if I try to reference the original form as, for instance

Forms![Album Main 2]![Tracks Entry 1]![Song No] = Me![Song Id]
is my original. However, if I attempt to use a variable, such as OpenArgs...

Forms!OpenArgs![Tracks Entry 1]![Song No] = Me![Song Id]

it will fail. I have also passed the OpenArgs into a string variable and
used it, but it fails also.

My need is this. I am building a very large and complex database of music
which requires that the operator search for and place the correct song into
an album or cd tracks table. Since there are two criteria which make a song
unique TITLE and COMPOSERS, this operator intervention is necessary to ensure
that the correct piece is attached to each compilation. The problem is that I
have to use Form_B with various versions of Form_A, hence the need to be able
to simply pass the calling form name and use it for the back reference.
(Form_B closes when the correct entry is chosen by the operator.) It would
seem to make more sense to use the method I have described rather than make
several copies of Form_B, each hard-coded for each calling Form_A version.

Any thoughts, tips, castigations? All appreciatied.

Thanks,
Don
 
A

Allen Browne

Don, a workaround here might be to use a public variable of type Control.
You set the variable to the particular control that you want to return the
value to before you open Form_B, and you can then just assing the results to
this control after the search.

This kind of thing:

1. In the General Declarations section (top) of a standard module:
Public gctlReturnControl As Control

2. In the code that opens FormB:
Set gctlReturnControl = Me.[Song Id]
DoCmd.OpenForm "FormB"

3. In the code that returns the value form FormB:
If Not (gctlReturnControl Is Nothing) Then
If Not IsNull(Me.[Song No]) Then
gctlReturnControl = Me.[Song No]
End If
Set gctlReturnControl = Nothing
End If
DoCmd.Close acForm, Me.Name
 
T

tina

try

Forms(Me.OpenArgs)![Tracks Entry 1]![Song No] = Me![Song Id]

or

Forms(StringVariableName)![Tracks Entry 1]![Song No] = Me![Song Id]

replacing StringVariableName with the name of a valid string variable, of
course.

hth
 
E

EyeTech

Tina's suggestion is a good one...while the first suggestion:
Forms(Me.OpenArgs)![Tracks Entry 1]![Song No] = Me![Song Id]

gave a type missmatch error (OpenArgs is type Variant)

using a string variable in this suggestion
Forms(StringVariableName)![Tracks Entry 1]![Song No] = Me![Song Id]

does the trick...

I was on the right track...I missed the parens! Duh.
Thanks Tina and Allen as well for your proposed fix...a little more work,
but interesting.

tina said:
try

Forms(Me.OpenArgs)![Tracks Entry 1]![Song No] = Me![Song Id]

or

Forms(StringVariableName)![Tracks Entry 1]![Song No] = Me![Song Id]

replacing StringVariableName with the name of a valid string variable, of
course.

hth


EyeTech said:
I have a need to pass a form name from one form to another in which the
original forms name will be used by the second form to populate a field on
the original after a search is done. I have been successful in passing the
form name in the OpenArgs parameter for the called form, but I have not been
able to use the arg or any other variable I might place the name in to
reference the original form.

If I pass "Form_A" in OpenArgs, I can confirm that it is succesfully passed
to Form_B, however, if I try to reference the original form as, for instance

Forms![Album Main 2]![Tracks Entry 1]![Song No] = Me![Song Id]
is my original. However, if I attempt to use a variable, such as OpenArgs...

Forms!OpenArgs![Tracks Entry 1]![Song No] = Me![Song Id]

it will fail. I have also passed the OpenArgs into a string variable and
used it, but it fails also.

My need is this. I am building a very large and complex database of music
which requires that the operator search for and place the correct song into
an album or cd tracks table. Since there are two criteria which make a song
unique TITLE and COMPOSERS, this operator intervention is necessary to ensure
that the correct piece is attached to each compilation. The problem is that I
have to use Form_B with various versions of Form_A, hence the need to be able
to simply pass the calling form name and use it for the back reference.
(Form_B closes when the correct entry is chosen by the operator.) It would
seem to make more sense to use the method I have described rather than make
several copies of Form_B, each hard-coded for each calling Form_A version.

Any thoughts, tips, castigations? All appreciatied.

Thanks,
Don
 
T

tina

re the OpenArgs data type - oops! using a variable works, as you noted; you
could probably also use

Forms(CStr(Me.OpenArgs))![Tracks Entry 1]![Song No] = Me![Song Id]

or possibly even

Forms("""" & Me.OpenArgs & """")![Tracks Entry 1]![Song No] = Me![Song Id]

....i didn't test either one to see for sure... :)

hth


EyeTech said:
Tina's suggestion is a good one...while the first suggestion:
Forms(Me.OpenArgs)![Tracks Entry 1]![Song No] = Me![Song Id]

gave a type missmatch error (OpenArgs is type Variant)

using a string variable in this suggestion
Forms(StringVariableName)![Tracks Entry 1]![Song No] = Me![Song Id]

does the trick...

I was on the right track...I missed the parens! Duh.
Thanks Tina and Allen as well for your proposed fix...a little more work,
but interesting.

tina said:
try

Forms(Me.OpenArgs)![Tracks Entry 1]![Song No] = Me![Song Id]

or

Forms(StringVariableName)![Tracks Entry 1]![Song No] = Me![Song Id]

replacing StringVariableName with the name of a valid string variable, of
course.

hth


EyeTech said:
I have a need to pass a form name from one form to another in which the
original forms name will be used by the second form to populate a field on
the original after a search is done. I have been successful in passing the
form name in the OpenArgs parameter for the called form, but I have
not
been
able to use the arg or any other variable I might place the name in to
reference the original form.

If I pass "Form_A" in OpenArgs, I can confirm that it is succesfully passed
to Form_B, however, if I try to reference the original form as, for instance

Forms![Album Main 2]![Tracks Entry 1]![Song No] = Me![Song Id]
is my original. However, if I attempt to use a variable, such as OpenArgs...

Forms!OpenArgs![Tracks Entry 1]![Song No] = Me![Song Id]

it will fail. I have also passed the OpenArgs into a string variable and
used it, but it fails also.

My need is this. I am building a very large and complex database of music
which requires that the operator search for and place the correct song into
an album or cd tracks table. Since there are two criteria which make a song
unique TITLE and COMPOSERS, this operator intervention is necessary to ensure
that the correct piece is attached to each compilation. The problem is that I
have to use Form_B with various versions of Form_A, hence the need to
be
able
to simply pass the calling form name and use it for the back reference.
(Form_B closes when the correct entry is chosen by the operator.) It would
seem to make more sense to use the method I have described rather than make
several copies of Form_B, each hard-coded for each calling Form_A version.

Any thoughts, tips, castigations? All appreciatied.

Thanks,
Don
 

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

Top