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 
if then with message box
Kim Nielsen 
      
3 years ago
I have looked through a number of videos, and I am having an issue trying to create the following check before a user closes the form. On pressing the close button, I want it to look into the RecordID field, if it is Null then a message box pops up asking the user there is no record field do you wish to close anyways and not save your work? Yes or no, if yes then close the form without saving anything, if user selects no the set focus to create a record id button. Now if there is a record ID then close and save the form. I am at a loss on how to reference the vbYes and vbNo in the statement. Please help
Scott Axton  @Reply  
        
3 years ago
Kim  

VBYesNoCancel was covered in Access Developer 3
Also, take a look at the IIF Function and the MsgBox videos and see what you come up with.

If you hit a wall let us know what you come up with and we'll help you troubleshoot.
Kim Nielsen OP  @Reply  
      
3 years ago
I have reviewed these videos, however none, connects the 2 together. I know what I want it to do. Just not sure how to write it. Basically I am looking at this as a preventative measure to prevent loss of data and errors popping up:
The first part checks to see if we have a record ID, if it doesnt then we have a choice close it and lose all data, or set the focus to the button to create the record ID. if there is a record ID then just close the form and save it. Where i am missing the issue is the message box decision process?

    DoCmd.SetWarnings False
        If IsNull(FDRecordID) Then
            MsgBox("There is no record ID do you want to close this form anyways?", vbYesNo, "Warning!") = vbNo
            Me.NewRecBtn.SetFocus
        Else
            DoCmd.Close acForm, (DeptNewRecordF), acSaveNo
        End If
    DoCmd.SetWarnings True
    DoCmd.Close acForm, (FDRecordF), acSaveYes

Kevin Robertson  @Reply  
          
3 years ago
You need nested If statements:

If IsNull(FDRecordID) Then
    If MsgBox("There is no record ID do you want to close this form anyways?", vbYesNo, "Warning!") = vbNo
        Me.NewRecBtn.SetFocus
    Else
        DoCmd.Close acForm, (DeptNewRecordF), acSaveNo
    End If
End If
Kim Nielsen OP  @Reply  
      
3 years ago
Well I did not i could do that, thank you will put that in my took kit for programing  thank you for this.

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/6/2026 12:06:01 PM. PLT: 0s