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 
Data Validation
Christopher Godfrey 
     
6 months ago
I'm encountering a logging issue related to form validation in Access. I'm using Me.Dirty = False in a button's click event (SaveDealBtn_Click) to trigger the Form_BeforeUpdate event for validation. The validation works correctly — if a required field is missing, it shows a MsgBox, cancels the update (Cancel = True), and sets focus back to the missing field.
However, after the validation fails and Me.Undo runs, the original Me.Dirty = False line throws error 2101 ("The setting you entered isn't valid for this property"). This is expected behavior after a cancel, but I’m using vbWatchdog to log all runtime errors, and it logs this 2101 error every time a user fails validation, even if it's handled.
This means my error log gets flooded with harmless validation-related 2101 errors — making it harder to track real issues. I've tried handling the error locally (On Error Resume Next, clearing Err, filtering by Err.Number = 2101, etc.), but vbWatchdog still catches and logs it.
I’d appreciate your insight on how to:
•Either prevent Me.Dirty = False from triggering after a validation cancel
•Or suppress/logically exclude this known error from vbWatchdog’s logging
Thanks in advance!
Here is my code:
Christopher Godfrey OP  @Reply  
     
6 months ago
DetailsPrivate Sub SaveDealBtn_Click()
    On Error GoTo SaveErr

    ' This line triggers BeforeUpdate ? validation
    If Me.Dirty Then Me.Dirty = False

    Exit Sub

SaveErr:
    If Err.Number = 2101 Then
        ' Known, expected validation failure — clear error so logger ignores it
        Err.Clear
        Resume Next
    Else
        ' Unexpected error — log or handle as needed
        MsgBox "Unexpected error: " & Err.Description, vbExclamation, "Save Error"
    End If
End Sub




DetailsPrivate Sub Form_BeforeUpdate(Cancel As Integer)

    If IsNull(Me!CustomerName) Or Trim(Me!CustomerName & "") = "" Then
        MsgBox "Customer Name is required.", vbExclamation, "Missing Information"
        Cancel = True
        Me!CustomerName.SetFocus
        Exit Sub
    End If

    If IsNull(Me!StockNumber) Or Trim(Me!StockNumber & "") = "" Then
        MsgBox "Stock Number is required.", vbExclamation, "Missing Information"
        Cancel = True
        Me!StockNumber.SetFocus
        Exit Sub
    End If

    If IsNull(Me!YearMakeModel) Or Trim(Me!YearMakeModel & "") = "" Then
        MsgBox "Year/Make/Model is required.", vbExclamation, "Missing Information"
        Cancel = True
        Me!YearMakeModel.SetFocus
        Exit Sub
    End If

    If IsNull(Me!ContractDate) Then
        MsgBox "Contract Date is required.", vbExclamation, "Missing Information"
        Cancel = True
        Me!ContractDate.SetFocus
        Exit Sub
    End If

    If IsNull(Me!StockTypeID) Or Me!StockTypeID = 0 Then
        MsgBox "Stock Type is required.", vbExclamation, "Missing Information"
        Cancel = True
        Me!StockTypeID.SetFocus
        Exit Sub
    End If

    If IsNull(Me!DealTypeID) Or Me!DealTypeID = 0 Then
        MsgBox "Deal Type is required.", vbExclamation, "Missing Information"
        Cancel = True
        Me!DealTypeID.SetFocus
        Exit Sub
    End If

    If IsNull(Me!DealCredit) Or Me!DealCredit = 0 Then
        MsgBox "Deal Credit is required.", vbExclamation, "Missing Information"
        Cancel = True
        Me!DealCredit.SetFocus
        Exit Sub
    End If

End Sub

Raymond Spornhauer  @Reply  
          
6 months ago
Christopher

Have you tried preventing the Save Button from being pressed before all the data is entered?

Your Save Button is trying to Set Me.Dirty to False, while your BeforeUpdate is saying to Cancel... on an error, these will conflict.

-Raymond

-Raymond

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 9:14:24 PM. PLT: 2s