Solved

Access field validation - Before Update event

Posted on 2014-01-22
1
540 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

22 Experts available now in Live!

Get 1:1 Help Now