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 Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Whats Wrong with This vba Code When I Open a Form
Roger Strate 
       
14 months ago
I have a form called "Ministers" that has a sub form called "FamilyMemberF". When I open the Ministers form I add the following code in the onload section so I can be notified when the "FamilyID" in the subform is blank:

If Forms!Minister.Form!FamilyMemberF = "" Then
MsgBox "There are no children in this home!"
Exit Sub
Else
DoCmd.OpenForm "FamilyMemberF",,,"FamilyID=" & FamilyID
End if

So far I am "stumped" any ideas?
Thanks
David Semon  @Reply  
      
14 months ago
I am not an expert by any means, but it looks like you are testing to see if a form is empty.  I don't think you can do that.  You have to test one of the controls on the form to see if it is empty.  Perhaps FamilyID.  There are several ways to determine if a form's controls have content.  Just a thought.
Roger Strate OP  @Reply  
       
14 months ago
You're right, my bad. I was trying to look up the FamilyId but didn't previously add it to this code. The corrected?? code is below.

If Forms!Minister.Form!FamilyMemberF!FamilyID = "" Then
MsgBox "There are no children in this home!"
Exit Sub
Else
DoCmd.OpenForm "FamilyMemberF",,,"FamilyID=" & FamilyID
End if
Roger Strate OP  @Reply  
       
14 months ago
Maybe this code might be more correct, but it still doesn't work.

If Forms!Minister!FamilyMemberF.Form!FamilyID = "" Then
MsgBox "There are no children in this home!"
Exit Sub
Else
DoCmd.OpenForm "FamilyMemberF",,,"FamilyID=" & FamilyID
End if
Roger Strate OP  @Reply  
       
14 months ago

Kevin Robertson  @Reply  
          
14 months ago
Try something like this:

    Dim ID As Variant
    
    ID = Forms!MinisterF!FamilyMemberF.Form!FamilyID
    
    If IsNull(ID) Or ID = "" Then
        MsgBox "There are no children in this home!"
    Else
        DoCmd.OpenForm "FamilyMemberF",,,"FamilyID=" & FamilyID
    End If


Does this work for you?

Review these videos:
    Value From a Form
    Value From Subform

For future reference: Please enlarge your images so we can actually see them.
Roger Strate OP  @Reply  
       
14 months ago
Thanks Kevin, I put the code on the Ministers form onload event but when I open the Ministers form I get the error message that it can't find FamilyMemberF. I checked the spelling and it is correct for that form. FamilyID is also spelled correctly.
Kevin Robertson  @Reply  
          
14 months ago
Is the name of the Subform object FanilyMemberF?
That is, the actual Subform control.
Roger Strate OP  @Reply  
       
14 months ago
No, FamilyMemberF. The error message I am getting is RunTime error 2465 "Microsoft Access can't find the field FamilyMemberF referred to in your expression" which is ID = Forms!Ministers!FamilyMemberF.Form!FamilyID. Ministers is the form name not MinisterF. Thank you for your help.
Jerry Fowler  @Reply  
       
14 months ago
Rodger, I see a typing error. above you have

Forms!Ministers!FamilyMemberF.Form!FamilyID

and Kevin had typed

Forms!MinisterF!FamilyMemberF.Form!FamilyID

so should it be Minister or MinisterF, I do this quite often
Roger Strate OP  @Reply  
       
14 months ago
I caught that too, the form is "Ministers", no F at the end. Also, the code does not work. Thanks for checking.

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

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: 5/7/2026 5:18:41 AM. PLT: 1s