Solved

Access field validation - Before Update event

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

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

680 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