Solved

ms access - Subform Referencing

Posted on 2014-11-29
10
155 Views
Last Modified: 2015-01-15
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
0
Comment
Question by:padrepio2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 26

Expert Comment

by:Nick67
ID: 40471908
Me!Subformname.Form!controlname.value is the syntax
! after .Form
0
 

Author Comment

by:padrepio2
ID: 40471915
Still same error message regardless of ! or .
0
 
LVL 18

Assisted Solution

by:Simon
Simon earned 500 total points
ID: 40471942
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:padrepio2
ID: 40471957
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
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40471988
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
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40472000
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
 
LVL 26

Expert Comment

by:Nick67
ID: 40472006
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
 
LVL 26

Expert Comment

by:Nick67
ID: 40472193
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
 
LVL 85
ID: 40472434
Here's a reference for this sort of thing:

http://access.mvps.org/access/forms/frm0031.htm
0
 

Author Closing Comment

by:padrepio2
ID: 40551517
Decided to work around issue although got closer to complete solution with this answer
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question