Solved

Access field validation - Before Update event

Posted on 2014-01-22
1
537 Views
Last Modified: 2014-01-22
I have a combo box which is validated in the Before update event.  If the value is invalid I want to revert to the original value, as if the user pressed ESC once.

I currently have:
Private Sub cboReportingSet_BeforeUpdate(Cancel As Integer)
    'verify that this group has same currency as others in this set

    Dim rs As Recordset
    Set rs = DB.OpenRecordset("Select * from [List_Of_Group/Division] where ReportingSet='" & Me.cboReportingSet & "'", dbOpenDynaset)
    If rs.RecordCount > 0 Then
        rs.MoveFirst
        If Nz(rs!ReportingCurrency, "") <> Nz(Me.txtReportingCurrency, "") Then
            MsgBox "You can't use this reporting set for this group.  Another group in this set has a conflicting currency.  All groups within a set must have same currency."
            Me.cboReportingSet.Undo
        End If
    End If
    rs.Close: Set rs = Nothing

End Sub

Open in new window


The undo does not remove the new value.  So, if it was originally A, user changes it to B, and this is not valid, I want to set value back to A.  How do I do this?
0
Comment
Question by:MonkeyPie
1 Comment
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 39801842
try using




       If Nz(rs!ReportingCurrency, "") <> Nz(Me.txtReportingCurrency, "") Then
            MsgBox "You can't use this reporting set for this group.  Another group in this set has a conflicting currency.  All groups within a set must have same currency."

            Cancel=true

            Me.cboReportingSet.Undo
        End If
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now