Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer 2    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
GoToControl on a subform
Robert Blanchette 
    
2 years ago
I want to use the DoCmd.GotoControl to check if a control is empty. However, it is on a subform. How do I do this?
Richard Rost  @Reply  
          
2 years ago
You don't want Empty. That's a special condition for a variant. What you probably mean is Null.

IsNull(FieldName)

And if the field is on a subform it would be:

IsNull(SubformName.Form!FieldName)
Robert Blanchette OP  @Reply  
    
2 years ago
Thanks very much for your prompt answer,
Note that I'm on a french version of Access. I don't think it makes any difference as far as VBA is concerned.

I tried to make a simple button with code that follows your suggestion for a field on a subform.

-----------------------------
Private Sub GoToControlButton_Click()

     DoCmd.GoToControl "F_SubInteret.Form!InteretID"

End Sub
---------------------------------

I get an error message that says that there is no field named F_Subinteret.Form!InteretID in the present record.

I'll include a screen shot that tries to show this.
It looks like I'm doing something wrong.
Robert Blanchette OP  @Reply  
    
2 years ago

Kevin Robertson  @Reply  
          
2 years ago
With DoCmd.GoToControl it has to be the actual field name.
For a field on a Subform use SetFocus.

    [F_SubInteret].Form!InteretID.SetFocus
Richard Rost  @Reply  
          
2 years ago
Yeah, GoToControl doesn't support that. You'd need multiple steps:

Docmd.Gotocontrol "F_SubInteret"
Docmd.Gotocontrol "InteretID"

Kevin Robertson  @Reply  
          
2 years ago
Yeah. I forgot about that. I must be getting old. LOL.
Sami Shamma  @Reply  
             
2 years ago
Don't mention getting old guys. I am 68 today.
Kevin Robertson  @Reply  
          
2 years ago
Happy birthday Sami
Richard Rost  @Reply  
          
2 years ago
Happy birthday. You don't look a day over 67. :)
Alex Hedley  @Reply  
           
2 years ago
Happy Birthday Sami
Sami Shamma  @Reply  
             
2 years ago
Thank you guys
Robert Blanchette OP  @Reply  
    
2 years ago
Thanks for your input.
However, I still can't get the result I wanted in my initial post. I wanted to check if a control on a subform was null, then take some action before the record was saved.

I tried your suggestions, first by simply creating buttons that would bring me to the control on the subform
1 (in yellow) DID NOT work with the "SetFocus"
2 (in yellow) DID work with the 2 steps gotocontrol
3 (in yellow) DID NOT work to check if the control on the subform was null

Please let me know what I'm doing wrong.
Thanks for your time. I'll include a screen capture and explanations on the next post.
Robert Blanchette OP  @Reply  
    
2 years ago

Richard Rost  @Reply  
          
2 years ago
OK, with regards to the SetFocus command, it is working. It just doesn't look like it's working. It is setting the focus on that field in that subform. However, your primary focus is still on the button that you're clicking on in the main form. So what you'd need to do is use two SetFocus commands: one to set the focus on the subform object itself, and then the second command would set the focus on the field in that form that you want. It's very similar to my two DoCmd.GoToControl commands.

OrderDetailF.SetFocus
OrderDetailF.Form!Quantity.SetFocus
Richard Rost  @Reply  
          
2 years ago
Now, as far as that BeforeUpdate event goes, that will only run once the user does something in that subform record. If they don't put anything in either field, the BeforeUpdate event is never triggered. So in this particular case, what you'd have to do is check to see if there are any subform items before the user is allowed to save the parent form. This is called checking for widows and orphans. Technically, you're looking for a widow of an order that has no detail items, for example. And I happen to have a video on that. Widows & Orphans
Richard Rost  @Reply  
          
2 years ago
And if you're checking to see if the field is null from the parent form, it all depends on what record the user is sitting on. So even if they add five records in the subform, if they're currently sitting on the blank new record on the bottom, it's going to return a null, so you can't just check to see if it's null. You have to check to see if there are any records related to that parent.
Robert Blanchette OP  @Reply  
    
2 years ago
Thanks very much for the time you spent helping me on this. I really appreciate.
Keep up  the good work.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 2.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 7:14:43 AM. PLT: 1s