473,379 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 6253
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Rey | last post by:
Howdy all. Appreciate your help with several problems I'm having: I'm trying to determine if the Visit subform (subformVisits) has a new record or been changed, i.e. dirty. The form that...
2
by: Salad | last post by:
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"...
3
by: Joshua Ammann | last post by:
Hi, (Using Access 2000) I have two tables, similar to Customers and Orders. (Not an exact parallel, but works for this example.) On a form showing customer data, there is a tab control. One...
1
by: sofakingfree | last post by:
I keep getting an invalid property assignment error when tring to reference a subform. All I am trying to do is substitute this: Forms!!.SetFocus for this: FormAndSubForm.SetFocus
6
by: Mat | last post by:
Dear all, What I want to do is be able to use a string to refer to a control on a subform. IE: Forms!("Form1!form2!controlA").name or
1
by: Eric | last post by:
Is it possible to create a mirror from 1st subform variable into 2nd subform variable.
2
by: David W. Fenton | last post by:
I think at various times we've all encountered this problem: A subform is on a main form. From the code of the main form we refer to some property of/control on the child form thus: ...
6
NeoPa
by: NeoPa | last post by:
Introduction The first thing to understand about Sub-Forms is that, to add a form onto another form takes a special Subform control. This Subform control acts as a container for the form that you...
3
by: Darin | last post by:
I have a problem I just can't figure out. I have a form with a subform, and the recordsource of the subform has criteria based on some unbound fields in the parent form so that data in the parent...
6
by: viperRider | last post by:
Another question to people smarter than me! LOL I have a form with a variable - Dim cboOriginator as TextBox - that holds the info about a textbox i click on. when i click on it, i have a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.