473,835 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6286
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(subFormNa me)!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.For m
Else
' This sets the form reference to the main form
Set frm = Forms!MF
Endif
Me!Text1 = frm!Text1

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

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

iQA/AwUBQIXB64echKq OuFEgEQJ5PACdHm UkG3DtKVIq1XKUc qEGPXrjl+UAoLLy
79LQ5qCE1RezVCM RyFWsBO4u
=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(subFormNa me)!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.For m
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
24900
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 contains the subform is named Clients. I have this code in the Add Client btn: If Forms!Clients.subformVisits!VisitDirty = True Then MsgBox "Visit subform is dirty!"
2
376
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" Endif Me.Text1 = Forms(strForm)!Text1
3
4156
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 of the tabs has a subform showing order data (in datasheet view). On the same tab there is an unbound textbox (next to the datasheet). I placed a
1
2951
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
2755
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
1395
by: Eric | last post by:
Is it possible to create a mirror from 1st subform variable into 2nd subform variable.
2
4293
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: Me!subForm.Form!txtTextBox and for some reason, in certain contexts, we get the error: Error 2455: You entered an expression that has an invalid reference
6
96287
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 want to act as a Sub-Form of the main one. That is to say, if you wanted frmB to act as a Sub-Form of frmA, then you would create a Subform control on frmA (in this example we'll call it sfmB). Subforms have a .Form property which contains a...
3
7706
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 form affects data in the subform. I've had this type of setup often, but I've run across a couple forms where this has caused an "enter parameter value" pop up for each reference to the parent control in the query when the main form is closed. ...
6
10839
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 calendar set up to "become visible" and show either the date in the field i just clicked on or todays date if null. all of this worked fine when i had the date fields in the same table as the rest of the data; but now i have this info in a separate table...
0
9803
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9652
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7766
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5804
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.