Solved

Access field validation - Before Update event

Posted on 2014-01-22
1
555 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
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.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

724 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