Subform opens before main form

Can I pass a value from the main form before the subform opens?

Can I have a public variable on the main form that passes a value to the 
sub-form when it opens? 


0
JimP
5/1/2007 2:50:26 PM
access.formscoding 7493 articles. 0 followers. Follow

8 Replies
1208 Views

Similar Articles

[PageSpeed] 1

JimP wrote:

>Can I pass a value from the main form before the subform opens?
>
>Can I have a public variable on the main form that passes a value to the 
>sub-form when it opens? 


No.

The usual way to do something like that is for the subform
to pull the value from the main form in the subform's Open
or Load event.  Use the Load event is you want are assigning
variable to a control's Value.

Since the main form variable is public, the code would
simply be:

	xx = Parent.variable

-- 
Marsh
MVP [MS Access]
0
Marshall
5/1/2007 4:03:21 PM
How do I refer to the main form, given that the sub-form could be in various 
main forms?

i.e. How do I know what the main form name is?


"Marshall Barton" <marshbarton@wowway.com> wrote in message 
news:c0pe33565vv7m8u8pniu4nf3c44nheld3b@4ax.com...
> JimP wrote:
>
>>Can I pass a value from the main form before the subform opens?
>>
>>Can I have a public variable on the main form that passes a value to the
>>sub-form when it opens?
>
>
> No.
>
> The usual way to do something like that is for the subform
> to pull the value from the main form in the subform's Open
> or Load event.  Use the Load event is you want are assigning
> variable to a control's Value.
>
> Since the main form variable is public, the code would
> simply be:
>
> xx = Parent.variable
>
> -- 
> Marsh
> MVP [MS Access] 


0
JimP
5/2/2007 1:20:11 PM
You don't need the name of the main form.  That's why you
use the Parent property.

Just in case you have some strange reason for getting the
name of the main form it's Parent.Name
-- 
Marsh
MVP [MS Access]


JimP wrote:

>How do I refer to the main form, given that the sub-form could be in various 
>main forms?
>
>i.e. How do I know what the main form name is?
>
>
>"Marshall Barton"  wrote
>> JimP wrote:
>>
>>>Can I pass a value from the main form before the subform opens?
>>>
>>>Can I have a public variable on the main form that passes a value to the
>>>sub-form when it opens?
>>
>>
>> No.
>>
>> The usual way to do something like that is for the subform
>> to pull the value from the main form in the subform's Open
>> or Load event.  Use the Load event is you want are assigning
>> variable to a control's Value.
>>
>> Since the main form variable is public, the code would
>> simply be:
>>
>> xx = Parent.variable
0
Marshall
5/2/2007 7:58:18 PM
Thank you - I didn't realize "Parent" was literal.

On the same issue, is it possible to use variables on the main form and pass 
the values to the sub-forms? Would this simply be declaring them public on 
the main form?

The use of sub-forms is new to me and I apologize for the long thread.

Jim

"Marshall Barton" <marshbarton@wowway.com> wrote in message 
news:m2rh33tbgnih9hm2ikln97qshn0sb1bp8c@4ax.com...
> You don't need the name of the main form.  That's why you
> use the Parent property.
>
> Just in case you have some strange reason for getting the
> name of the main form it's Parent.Name
> -- 
> Marsh
> MVP [MS Access]
>
>
> JimP wrote:
>
>>How do I refer to the main form, given that the sub-form could be in 
>>various
>>main forms?
>>
>>i.e. How do I know what the main form name is?
>>
>>
>>"Marshall Barton"  wrote
>>> JimP wrote:
>>>
>>>>Can I pass a value from the main form before the subform opens?
>>>>
>>>>Can I have a public variable on the main form that passes a value to the
>>>>sub-form when it opens?
>>>
>>>
>>> No.
>>>
>>> The usual way to do something like that is for the subform
>>> to pull the value from the main form in the subform's Open
>>> or Load event.  Use the Load event is you want are assigning
>>> variable to a control's Value.
>>>
>>> Since the main form variable is public, the code would
>>> simply be:
>>>
>>> xx = Parent.variable 


0
JimP
5/3/2007 2:37:10 PM
That's the same question we've been discussing.  Because the
main form is initialized before any subforms, you can not
reliably "pass" values (of any kind) to a subform until all
the subforms have been initialized.  That's why I keep
saying that the subform's should "pull" the values from the
mainform.

The important point here is that Public **variables** in a
form module are properties of the form object and can be
referenced as I indicated earlier.

If you are using the word "variable" only loosely and mean
something other than a VBA variable in a module, then try to
explain more about what you are really trying to accomplish.
-- 
Marsh
MVP [MS Access]


JimP wrote:
>On the same issue, is it possible to use variables on the main form and pass 
>the values to the sub-forms? Would this simply be declaring them public on 
>the main form?
>
>"Marshall Barton"  wrote
>> You don't need the name of the main form.  That's why you
>> use the Parent property.
>>
>>
>> JimP wrote:
>>>How do I refer to the main form, given that the sub-form could be in 
>>>various
>>>main forms?
>>>
>>>i.e. How do I know what the main form name is?
>>>
>>>> JimP wrote:
>>>>>Can I pass a value from the main form before the subform opens?
>>>>>
>>>>>Can I have a public variable on the main form that passes a value to the
>>>>>sub-form when it opens?
>>>>
>>>
>>>"Marshall Barton"  wrote
>>>> No.
>>>>
>>>> The usual way to do something like that is for the subform
>>>> to pull the value from the main form in the subform's Open
>>>> or Load event.  Use the Load event is you want are assigning
>>>> variable to a control's Value.
>>>>
>>>> Since the main form variable is public, the code would
>>>> simply be:
>>>>
>>>> xx = Parent.variable 
0
Marshall
5/3/2007 3:53:06 PM
I think I get it - thanks for your help.


"Marshall Barton" <marshbarton@wowway.com> wrote in message 
news:jo0k33tff46cbm97vcvue4padgadhrglvj@4ax.com...
> That's the same question we've been discussing.  Because the
> main form is initialized before any subforms, you can not
> reliably "pass" values (of any kind) to a subform until all
> the subforms have been initialized.  That's why I keep
> saying that the subform's should "pull" the values from the
> mainform.
>
> The important point here is that Public **variables** in a
> form module are properties of the form object and can be
> referenced as I indicated earlier.
>
> If you are using the word "variable" only loosely and mean
> something other than a VBA variable in a module, then try to
> explain more about what you are really trying to accomplish.
> -- 
> Marsh
> MVP [MS Access]
>
>
> JimP wrote:
>>On the same issue, is it possible to use variables on the main form and 
>>pass
>>the values to the sub-forms? Would this simply be declaring them public on
>>the main form?
>>
>>"Marshall Barton"  wrote
>>> You don't need the name of the main form.  That's why you
>>> use the Parent property.
>>>
>>>
>>> JimP wrote:
>>>>How do I refer to the main form, given that the sub-form could be in
>>>>various
>>>>main forms?
>>>>
>>>>i.e. How do I know what the main form name is?
>>>>
>>>>> JimP wrote:
>>>>>>Can I pass a value from the main form before the subform opens?
>>>>>>
>>>>>>Can I have a public variable on the main form that passes a value to 
>>>>>>the
>>>>>>sub-form when it opens?
>>>>>
>>>>
>>>>"Marshall Barton"  wrote
>>>>> No.
>>>>>
>>>>> The usual way to do something like that is for the subform
>>>>> to pull the value from the main form in the subform's Open
>>>>> or Load event.  Use the Load event is you want are assigning
>>>>> variable to a control's Value.
>>>>>
>>>>> Since the main form variable is public, the code would
>>>>> simply be:
>>>>>
>>>>> xx = Parent.variable 


0
JimP
5/3/2007 5:49:06 PM
"xx = Parent.variable" is giving me a "Application-defined or object defined 
error" Any suggestions?



"Marshall Barton" <marshbarton@wowway.com> wrote in message 
news:c0pe33565vv7m8u8pniu4nf3c44nheld3b@4ax.com...
> JimP wrote:
>
>>Can I pass a value from the main form before the subform opens?
>>
>>Can I have a public variable on the main form that passes a value to the
>>sub-form when it opens?
>
>
> No.
>
> The usual way to do something like that is for the subform
> to pull the value from the main form in the subform's Open
> or Load event.  Use the Load event is you want are assigning
> variable to a control's Value.
>
> Since the main form variable is public, the code would
> simply be:
>
> >
> -- 
> Marsh
> MVP [MS Access] 


0
JimP
5/8/2007 1:21:45 PM
JimP wrote:

>"xx = Parent.variable" is giving me a "Application-defined or object defined 
>error" Any suggestions?


What are you using for "xx"?  How is it declared in the
subform?

How did you declare "variable" in the main form?

If you would post the actual names of the forms, objects and
variables you are using, we could avoid all the ambiguity
caused by generalized names.

-- 
Marsh
MVP [MS Access]
0
Marshall
5/8/2007 4:04:13 PM
Reply:

Similar Artilces:

data form
Is there a way, with a data form, to allow the user to only input one record. For instance, I have a macro that opens the data form, uses "SendKeys" statment to start a new record. It then relies on the user to press Enter at the end of the record and then the close button to exit from the data form. Is there a way for it to close after they've entered the last field? TIA Steve You can't program the built-in data form, but you could build your own, or try John Walkenbach's Enhanced Data Form. http://j-walk.com/ss/dataform/index.htm Steve Simons wrote: > Is...

Unable to open outlook today in outlook 2002
I just installed Outlook 2002. Setup email accounts. Hotmail shows however, when I click to open/expand Outlook today I get this message and nothing shows, no calendar, etc... Unable to expand the folder. The set of folders could not be opened. Could not open the item. Try again. I am running Microsoft Windows XP Home Edition Service Pack 2 on a Compaq AMD Laptop. What other kind of mail account(s) did you setup? "Whitney" <Whitney@discussions.microsoft.com> wrote in message news:347B0CD2-679C-4EFA-AF32-DE029C181E00@microsoft.com... >I just installed Outlo...

Excel Chart opening in text format
Due to some virus problem, i had to format my pc and reinstall everythng. But now when i open some excel files with charts in it, it opens as a delimited text file and charts are not displayed. Excel version is 97. Can somebdy pls help. These are important files. Rosie ...

form cache file not valid
I receive the following error message when trying to email from the internet... does it say frmcache.dat? if so, delete it and it will recreate the frmcache.dat when you reopen outlook. -- Robert Cohen A legend in his own mind -- <anonymous@discussions.microsoft.com> wrote in message news:1371401c3f725$6b989c00$a501280a@phx.gbl... > I receive the following error message when trying to email > from the internet... ...

How do I open an OpenDocument Text (.odt) in Word 2003?
I wonder if there is a way to open an .odt document in Word 2003. You don't. Open it in OpenOffice and save it in .doc format. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "HaTT" <HaTT@discussions.microsoft.com> wrote in message news:7CC31800-B8AC-4262-AE9A-AE35D62B88BD@microsoft.com... >I wonder if there is a way to open an .odt document in Word 2003. > You'll need a converter - http://www.mydigitallife.info/2007/02/07/download-openxml-translator-odf-converter-add-in-for-office-wor...

Form Question 12-31-07
I have a command button on my form I use to look at the "Datasheet view" after closing the datasheet it doesn't return back to the form it returns me to the switchboard. Private Sub Command23_Click() On Error GoTo Err_Command23_Click DoCmd.OpenForm "frmScanlog", acFormDS Exit_Command23_Click: Exit Sub Err_Command23_Click: MsgBox Err.Description Resume Exit_Command23_Click End Sub Thanks for your help. I believe since the datasheet veiw of the form is just another way to see the form, when you click the cmd button it doesn't open a new insta...

TM-T88IV not opening Cash Drawer with Vista
I have installed Microsoft RMS 2.0 on Windows Vista. I had issues installing my EPSON printer TM-T88IV. Now it work as "OPOS" device with "OPOSADK250E" driver. Now the receipt prints but the problem is that the cash drawer wont open when the receipt is printed. The cash drawer is APG VB 320-BL1616. I changed the cable.The health test of cash drawer is passed. there are vista drivers for the TM-T88IV but according to Microsoft it hasnt been determined if it is compatible. but anyways the driver that I download called "OPOSADK250E" Any ideas whats wrong ...

Cant open Hotmail emails with attchmnts in Outlook/Outlook Connect
I can't open any Hotmail emails with attachments in Outlook 2007 with Outlook Connector installed on my laptop. I can open Hotmail emails without attachments no problem. I am downloading my messages through dial-up. Outlook Connector initially tries to download the message while checking for viruses but stops and gives the error, "Cannot open this item. The network connection is unavailable or interrupted. Please try again later." Interestingly enough, when I bring my laptop to where there's a high-speed connection and connect wirelessly, I am then able to downl...

Form Customization with XML ?
Is it possible to edit the XML to allow a normally unallowed field into the searchable fields? I would like to add the Step Name to the Opportunities. I can see it in the Entity XML viewer when I edit the Advanced Find, but I cannot add it to the displayed columns. Thank you. ...

link to a website on a form
Is is possible to create a link to a website on a form? If it is possible how do I go about doing this. Thank you for your time. There are different way to approach this. First Option Create a label and set the Hyperlink Address Property Second Option Create a lable and create an On Click event using the FollowHyperlink Method and there are even other options... -- Hope this helps, Daniel Pineault http://www.cardaconsultants.com/ For Access Tips and Examples: http://www.devhut.net Please rate this post using the vote buttons if it was helpful. "Gina" wr...

Form calculating troubles
I have a form that I list merchandise with prices. This automatically figures tax and and quanity I enter to give me a item total. At the bottom of the page it gives me a total of all the merchandise listed. This has been working great for the past year but suddenly the totals at the base of the page will not calculate. At the bottom left hand corner it say Calculating..... but never seems to finish. The weird thing is that if I minimize access, then bring it up again the total magically appears. The totals also appear when I print out the page. Refreshing the form doesnt seem to do...

Internet Explorer hangs on opening
Just today IE 8 would no longer open the home page (or any other website). I removed IE 8 and went back to IE 7 and problem is the same. (Also using Outlook (which works fine) when clicking on a hyperlink to a web address then Outlook hangs too) I've tried resetting the internet options, also restoring system to earlier in the week, but all make no difference. Lastly I'm using XP. Advice eagerly welcomed! Steve Lawes Hi, Work through this article: Tips for solving problems with Internet Explorer [IE7 - IE8]: http://windows.microsoft.com/en-US/windows7/Tips-fo...

Click to Open Record from an Unbound Text Box
Hi All, Getting close I think. I have an unbound text box on a subform that lists items from a table (tblSENEIncidentLog2008). The subform is on my Main Form. I am trying to make it so when I click on an item from my ListBox, it loads the form and goes to that record. Right now, when I click on an item on the subform FROM MY MAIN MENU, it opens the form, but it only goes to the FIRST record of the form and shows Filtered. When I click on it with JUST the subform open, it seems to work fine. This is what I have in my List box (ListSAR) on the subform: In the After Update: Private S...

Survey form for Outlook?
I'm part if the IT support for the Hospice I work at. We are thinking of doing a survey on "How are we doing?". I'm thinking it would be neat if we could make it an Outlook (we are running Outlook 202 and Exchange 5.5) form that the user could respond, fill in and send back. Any thoughts on any existing forms/programs that would let us do that? -- Regards, Hank Arnold ...

Visual Basic ADODB Open Connection Make Table Query
I have the following code: - the code runs well, I get a message saying connection is open, but when I try to run the make table query I still get the login prompt - how do I avoid the login prompt? Many thanks! Dim qryArch112 As String qryArch112 = "" qryArch112 = "select DBOBJECTS_UDWEBFORMS_ARCHFRM_112_VIEW.PROPOSAL INTO tblArch112 FROM DBOBJECTS_UDWEBFORMS_ARCHFRM_112_VIEW;" '---open UD01 Dim oConn3 As ADODB.Connection Set oConn3 = New ADODB.Connection Dim sr As String sr = "pr01" If (udun <> "" And udpwd <>...

Export a single record directly from record form into excel, etc
I would like to have the ability to export a single record directly from the record form into excel and it would export the contents of all the tabs in the form. Once exported into excel, the tabs in Excel would depict the tab names in CRM with the exact same data on each tab. So the data format in CRM would be mirrored in the import to Excel. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow ...

Access Denied
Hi, I have one user in my organisation that when she tries to open at attachment (word document or PDF) in the notes section of any entity an error message stating "Access Denied, Invalid Operation" appears within the notes 'frame'. It only happens when using the Outlook client (not the web client). Her client and the server has had Update Rollup 7 applied (CRM 4.0, SQL 2005). I have also reconfigured, run diagnostics and removed any other outlook add-ins to no avail. Has anyone had this problem before and is there any way to fix it? Thanks If anyone else has this problem...

Forms
I am trying to modify an existing form that I have created but whenever I try to "Design a Form", I get an Expression Service error stating that the Expression Service did not start and the form could not be opened. I have run the Detect and Repair, removed\reinstalled Outlook and removed\reinstalled Office 2003 and I still have not been able to resolve this issue so I was hoping someone may have some ideas to resolving this. Thanks! Geoff ...

CRM should provide multiple Forms per Entity
This will help us position MSCRM as a platform for business applications. It will also enhance the capabilities of CRM in a multi-tennacy out-sourced contact center environment (where the contact center is working for multiple clients and thus has to collect different information per client). Having multiple Forms will allow us to provide each process with the information required for that application. A nice to have would be the opportunity to link a Form to a Role (thus creating the ability to shield information from certain users). -- Richard Fransen Newtel Essence Microsoft CRM Cert...

input mask formatting is lost when tables are formed to a union qu
I have set an input mask for the fax number text fields of 2 similar tables. When the tables are joined to form a union query, the formatting is not accurate. Some fax numbers contain the proper formatting of (123) 456-789 while others read 123456789. What could be causing this to happen? Susan, I just tried a union query with 2 different tables where both had fax numbers formatted as (123) 456-789. The resulting query had all the fax numbers formatted as (123) 456-789, - I couldn't reproduce your problem with my simple tables. Please post the SQL of your union query and we might b...

Subform/Subquery
I have a form that is tied to my projects table - there is a subquery on the form that is based on a 'top 5' query of the five most recent projects. When the form opens, the record displayed is the most recent project, so there is some redundancy, as it shows the detail for the active record which when the form opens is the most recent project created, but that is also the first project shown on the list of the 5 latest projects created. Is there a way I can just show not the latest project created, but the one before that, and so on - 5 projects total in my subform/subquery ? Here is...

Unable to open a 82 KB XLSM file due to "Too many different cell formats" & "Converter failed to open the file." errors.
Hello. I received a 82 KB XLSM (macro version?) file from a colleague. I tried to open it in my updated (as of last Tuesday) MS Office 2003 Pro. SP3, with its compatibilty pack. Excel Office SP3 (v11.8302.8221 SP3) failed to open it. When opening it, I saw "File conversion in progress" dialog box for a second, "Too many different cell formats" twice, and then "Converter failed to open the file." I asked another coworker who had old Office 2003 (not updated) and the compatbility pack. She got the same errors BUT was able to see the read the contents unlik...

can not open information store
I have one user that when they open their Outlook 2k (that connects to our Exchange Server 2k), she gets a message saying "can not open Information store" Everybody else is doing just fine. I removed the Exchange from her outlook, restarted the machine, re selected Exchange (from Outlook properties), but It gives the same answer. What's up?? ...

Restore default form to Contacts? Outlook 2007
I tried out a 3rd party app for Outlook 2007 and decided against using it. Unfortunately, it changed the Ribbon (maybe the form?) for all my thousands of contacts. As a result I can no longer view Details or Activities. New contacts created are OK. Is there a way to restore the default form and Ribbon for these contacts? Thanks. -- Lew See if http://www.publicshareware.com/download/DocMessageClass.zip gets you change the form. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.c...

Linked forms contd
I tried using this code from Arvin however I get a type mismatch error. I thought it may be a setting in the tables however they are both long interger. Any ideas Sub cmdOpen_Click() DoCmd.OpenForm "Memo",,,,"customerid=" & Me.customerid End Sub On the memo form set the DefaultValue of the customerid textbox to: =Forms!FirstFormName!customerid Now, if there is a matching record it opens to that record, if not, it creates one with an id equal to the one on the calling form. ...