ms access - Subform Referencing

Hi, been experiencing difficulties referencing the value on the subform on the attached snapshot.  

In order to ensure I had used the correct syntax, simply wanted the value of the 'PrimaryID' field on the subform named 'SpecificActivitiesHazardsFORM' to appear in a MsgBox  

Resultant error keeps popping up upon clicking Command_65.  Code also pictured.  

Can anyone help with this issue?
Untitled.png
padrepio2Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
SimonConnect With a Mentor Commented:
Hmm. You've probably tried this already..
1. Compact and repair your db then try again

2. - check the project references in the VBE Tools menu. I've had problems with objects that are defined in more than one DLL (e.g. format function. "Form" may well be another one that is defined in more than one library and has different properties/methods depending on which DLL is taking precedence). The order of the references can be critical, and odd problems can be resolved by unchecking and re-adding references. Most Access DBs will have no more than 4 or 5 references unless interacting with some industry-specific components.

2. Check that the control on the subform has control name PrimaryID (as opposed to txtPrimaryID or something else).
3. Create a tiny new form with a single unbound control on it and drop that on main form as a subform and try to refererence it
4. Try debug.print instead of msgbox and try assigning the control value to a variable of type variant first

If still stuck after the above, please provide some further details to help us...
Are both your main and subforms bound to tables/queries?
Is there a parent/child relationship set up between the two forms?  
Were the forms created using the forms wizard?
Access and operating system version?
Is it a new database or converted from an older version?
0
 
Nick67Commented:
Me!Subformname.Form!controlname.value is the syntax
! after .Form
0
 
padrepio2Author Commented:
Still same error message regardless of ! or .
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
SimonConnect With a Mentor Commented:
Check that the control name of the subform (on the main form) is actually the same as the name of the subform object itself. It is the former name that you should be using to refer to it. They are not necessarily the same.

See also http://support.microsoft.com/kb/113352
It is also important to note that when you are referring to controls on a subform, you must specify the value contained in the ControlName property of the subform control. The ControlName property should not be confused with the SourceObject property for a subform control. The SourceObject property is used to indicate which subform to use in the subform control. The ControlName property is used to specify the name by which the subform control is referenced. ControlName is typically set the same as the SourceObject, but it does not have to be.
i.e. Switch to design mode on your main form and click the edge of the subform container, then check the control name in the properties. If it is not "SpecificActivitiesHazardsFORM" you'll have found the cause.

Final thought: fix the error on your main form the '#Size!' error which looks like a calculated field. Probably unrelated, but errors in the main form muddy the waters.
0
 
padrepio2Author Commented:
SpecificActivitiesHazardsFORM is the name when I select the subform.  Was aware of this potential issue through my research into the error.


Removed the control with the '#Size!' error but made no difference

Thanks for trying
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
Before the message box, try

On error resume.next

The reason is this sub may be running when the form is not ready to be worked with. This just shot in the dark.
0
 
Nick67Commented:
Dumb question.
You actually have a control with the property id on the form?

Can you use the correct syntax to refer to ANY control on the subform, or it fails for them all?
0
 
Nick67Commented:
Sorry, my bad
Me!Subformname.Form!controlname.value is not right
Me.SubformControlName.Form!ControlName.Value

Working sample of the syntax attached
SubformReference.mdb
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Here's a reference for this sort of thing:

http://access.mvps.org/access/forms/frm0031.htm
0
 
padrepio2Author Commented:
Decided to work around issue although got closer to complete solution with this answer
0
All Courses

From novice to tech pro — start learning today.