(feel kinda stupid not being able to EVER get this one right... never-the-less)
ought to be easy: on a Main Form, I have a bound control,
behind it, this code in the BeforeUpdate event (I could move it to the NotInList event - if that makes more sense):
it contains the line: Me.ActiveControl.Undo, but it does not "UNDO"
(I'm using me.ActiveControl in lieu of the control's name as I will eventually be using this code several time for different controls on this form...)
Code:
Private Sub cboEnergyCode_BeforeUpdate(Cancel As Integer)
Dim blnExistingStandard As Boolean
blnExistingStandard = DCount("[strCode]", "tblCodes", "[strCode] = '" & Me.ActiveControl & "'") > 0
If Not blnExistingStandard Then
gsMsgTitle = "UNRECOGNIZED CODE"
gsMsgText = "'" & UCase(Me.ActiveControl) & "' is not yet in the Master Database;" _
& vbCrLf _
& vbCrLf _
& vbCrLf & "Do you want to add it?" _
& vbCrLf _
& vbCrLf & "(If you do not, it can still be used in this project; but it will not be available as a pull-down for future ones)"
gsMsgResponse = MsgBox(gsMsgText, vbQuestion + vbYesNoCancel + vbDefaultButton1, gsMsgTitle)
Select Case gsMsgResponse
Case Is = 6 'yes, ADD to the MDb
'<...>
Case Is = 7 'no, just use in this project
'<...>
Case Else 'cancel, clear entry
Me.ActiveControl.Undo '<--- this line executes without error, yet the control's value remains the same...
End Select
End If
End Sub
as always with appreciation in advance,
m.