Avatar of OGSan
OGSanFlag for United States of America

asked on 

Form works okay on its own - but konks out as a Subform

I have a form that works just fine when executed on its own.  It simply uses an Empl ID that is entered and then retrieves rows from a job history table after a button is clicked.  Let's call it frm_Job.  Then, I created a frm_Main with tabs, and used the Subform control to define frm_Job on the first tab as its Source Object.  Now when I enter in an Empl ID and click the button on frm_Job - it doesn't work.  When the button is clicked, it prompts me to "Enter Parameter Value ?" for the query.  If I do that - it works okay...so it doesn't seem to be picking up the entry off of the Subform field.  Weird.  As I said, if I open the frm_Job directly, it runs fine.  Is there anyone who can clarify what's going on here?  (I'll return to this after the weekend - I'm braindead now, but will award points based on first correct response.  TIA!)
Microsoft Access

Avatar of undefined
Last Comment
harfang
ASKER CERTIFIED SOLUTION
Avatar of harfang
harfang
Flag of Switzerland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Rey Obrero (Capricorn1)
slight correction
 Forms!frm_Main!sub_Job!txt_Empl_ID

should be

 Forms!frm_Main!sub_Job.form!txt_Empl_ID
Avatar of harfang
harfang
Flag of Switzerland image

Well, both work. But the second version is perhaps a bit more didactic (^v°)
Avatar of wiswalld
wiswalld
Flag of United States of America image

When refering to a subform value should be

forms!mainform.subform.form.field

When refering to a main form from subform;

forms!mainform.field
Avatar of harfang
harfang
Flag of Switzerland image

Hmm. Consider this Immediate window session (with the appropriate form loaded)

? TypeName(Forms)
Forms
? TypeName(Forms!frmForm)
Form_frmForm
? TypeName(Forms!frmForm.Form)
Form_frmForm
? TypeName(Forms!frmForm.Form.Form)
Form_frmForm
? TypeName(Forms!frmForm!subForm)
SubForm    <--- *control*
? TypeName(Forms!frmForm!subForm.Form)
Form_fsubForm   <--- *form*
? TypeName(Forms!frmForm!txtField)
Textbox
? TypeName(Forms!frmForm!subForm!txtField)
Textbox
? TypeName(Forms!frmForm!subForm.Form!txtField)
Textbox
? TypeName(Forms!frmForm!subForm.CurrentRecord)
[Run-time error '438']
? TypeName(Forms!frmForm!subForm.Form.CurrentRecord)
Long

As you see, an item of the Forms collection is directly a form object (of the right sub-type). However, a subform object is just that: a subform control. However, fields on the subform can be found directly from the subform object or from the actual form displayed. This is not true for other specific form properties, such as CurrentRecord.

Technically, this difference is due to the fact that the SubForm control does not necessarily display a form. It can display a plain query or a table just as well, or be momentarily unbound. However, as control, it always has a default collection called .Controls(). So that:

? TypeName(Forms!frmForm!subForm.Controls)
Controls   <--- always works!
? TypeName(Forms!frmForm!subForm.Form.Controls)
Controls or [Run-time error '2467']

So adding explicitly .Form is neither a "correction" nor something that "should be", it's only a syntactic variant, with a slightly different meaning... not necessarily better.

Does that clear things up a bit?
(°v°)
Avatar of harfang
harfang
Flag of Switzerland image

wiswalld,

> When refering to a main form from subform:

Me.Parent.txtField    (VB only)
Form.Parent.txtField    (VB or Jet)

(°v°)
see this links
How to refer to a control on a subform or subreport
http://support.microsoft.com/?kbid=209099

Refer to Form and Subform properties and controls
http://www.mvps.org/access/forms/frm0031.htm

Avatar of OGSan
OGSan
Flag of United States of America image

ASKER

Points go to harfang!  When I first tried inserting the frm_Main into my query reference - it STILL didn't work.  But after removing the original name of the stand-alone frm_Input and using it's (default) subform name of "Child3" - it worked!  I learned something from this exercise.  Thank you for taking the time to share your understanding with the rest of us!
Avatar of harfang
harfang
Flag of Switzerland image

Thanks and success with your subform!
(°v°)
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo