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 Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Update Button
Debby Lawrence 
     
2 years ago
Hi, I have a form which ADDs/Updates Insurance Cases.  Client asked for an OK button which can be clicked after updating a field or Adding new case information.  I added an "OK" button closes the form and returns to the Main Menu if clicked.  I am using DoCmd.Close and this works.  BUT if there is a validation error (Checked for in Before Update) I need to prevent the Close until the field in question is populated.  I have tried a few things which don't work - any Ideas?  
BEFORE UPDATE CODE: (the validation of CaseDocFolder depends on the Investigator ID not = 0;  0 is the default if the user leaves the field blank when Adding a Case)
    If InvestigatorID = 0 Then
        Exit Sub
    End If
    If IsNull(CaseDocFolder) Then
        MsgBox "The Active Folder name must be entered if an Investigator has been
        allocated"
        Cancel = True
        Exit Sub
    End If
Richard Rost  @Reply  
          
2 years ago
I would suggest just getting rid of the Validation Rule and doing your own validation in the BeforeUpdate event itself.
Debby Lawrence OP  @Reply  
     
2 years ago
hi Richard I have done all validations in the BeforeUpdate event but the OK button's Click Event (Docmd.Close)  Pops up the error, cancels the changes and closes the form - I don't want the form to close if there is a validation error.  How do I prevent it from closing in the OK button Click Event
Matt Hall  @Reply  
          
2 years ago
What if in the "OK" button_click event, you start with me.refresh to save the record?  You could run through validation again, msgbox / exit sub if any validation fails, and close if everything passes.
Debby Lawrence OP  @Reply  
     
2 years ago
Hi I tried me.refresh (in Event)  - error: no current record - which makes sense.  Instead of going back to the drawing board to achieve what I need to I found the following coding on one of the forums & it works so problem solved.  Now the form will not close until the correction is made.  Good to know for the future.
       Private Sub OKBtn_Click()
           On Error GoTo Err_OK
           DoCmd.RunCommand acCmdSaveRecord
           DoCmd.Close  
     Exit_OK:
           Exit Sub
     Err_OK:
         MsgBox Err.Description
        Resume Exit_OK



This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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 12:52:20 AM. PLT: 0s