[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

Access field validation - Before Update event

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
MonkeyPie
Asked:
MonkeyPie
1 Solution
 
Rey Obrero (Capricorn1)Commented:
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now