472,118 Members | 1,097 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,118 software developers and data experts.

Referring to subform via variable?

I have a sub routine that I'd like to use to get data from a main form
or from a subform preferably using 1 variable. Ex:

If Me.OpenArgs = "SF" Then
strForm = "MF!SF"
Else
strForm = "MF"
Endif
Me.Text1 = Forms(strForm)!Text1

This doesn't work, sadly. I know that I can get the value by getting
Me.Text1 inside of each part of the if statement. Is there a way to do
this or should I just separate the sub into two parts; data from a
single form, data from a subform.

Nov 12 '05 #1
2 6088
Salad wrote:
I have a sub routine that I'd like to use to get data from a main form
or from a subform preferably using 1 variable. Ex:

If Me.OpenArgs = "SF" Then
strForm = "MF!SF"
Else
strForm = "MF"
Endif
Me.Text1 = Forms(strForm)!Text1

This doesn't work, sadly. I know that I can get the value by getting
Me.Text1 inside of each part of the if statement. Is there a way to do
this or should I just separate the sub into two parts; data from a
single form, data from a subform.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here we run into the problem of form vs. subform. When a form is a
SourceObject of a subform control it is not considered an open form.
Therefore, referring to a subform as Forms(subFormName)!Text1 will not
work, 'cuz Forms() only refers to open forms.

However, you can set up a form reference to reference the appropriate
form. E.g.:

Dim frm As Form
If Me.OpenArgs = "SF" Then
' This sets the form reference to the sub-form
Set frm = Forms!MF!SF.Form
Else
' This sets the form reference to the main form
Set frm = Forms!MF
Endif
Me!Text1 = frm!Text1

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQIXB64echKqOuFEgEQJ5PACdHmUkG3DtKVIq1XKUcqEGPX rjl+UAoLLy
79LQ5qCE1RezVCMRyFWsBO4u
=w228
-----END PGP SIGNATURE-----

Nov 12 '05 #2
MGFoster wrote:
Salad wrote:
I have a sub routine that I'd like to use to get data from a main form
or from a subform preferably using 1 variable. Ex:

If Me.OpenArgs = "SF" Then
strForm = "MF!SF"
Else
strForm = "MF"
Endif
Me.Text1 = Forms(strForm)!Text1

This doesn't work, sadly. I know that I can get the value by getting
Me.Text1 inside of each part of the if statement. Is there a way to
do this or should I just separate the sub into two parts; data from a
single form, data from a subform.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here we run into the problem of form vs. subform. When a form is a
SourceObject of a subform control it is not considered an open form.
Therefore, referring to a subform as Forms(subFormName)!Text1 will not
work, 'cuz Forms() only refers to open forms.

However, you can set up a form reference to reference the appropriate
form. E.g.:

Dim frm As Form
If Me.OpenArgs = "SF" Then
' This sets the form reference to the sub-form
Set frm = Forms!MF!SF.Form
Else
' This sets the form reference to the main form
Set frm = Forms!MF
Endif
Me!Text1 = frm!Text1


Mil Gracias, MG.

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sofakingfree | last post: by
2 posts views Thread by David W. Fenton | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.