Don't allow AfterUpdate in Combo Box

I have an AfterUpdate action in a combo box that works just fine. Now, I am needing to first check to see if there is a value in a text box before running the AfterUpdate code.

Combo box name: OverrideLetterType
Text box name: DateLetterSent

Basic logic needed: If IsNull(DateLetterSent) Then
Run the code to override letter type
Else
show a message box saying "You can't override a letter type that has already been sent"
End If

Thanks for any suggestions.
Dale LoganConsultantAsked:
Who is Participating?
 
mbizupCommented:
However... do you want to actually cancel/undo the combo box's update?  If so your check belongs in the BEFORE update event like this:

Private Sub OverrideLetterType_BeforeUpdate(Cancel as Integer)
If NOT IsNull(DateLetterSent) Then
   MsgBox "You can't override a letter type that has already been sent"
   Me.OverrideLetterType.Undo
   Cancel = true
End If
End Sub

____

Or if you simply want to prevent the user from using theis combo box after a letter has been sent,  you can conditionally lock it down.

If that is something that fits your needs you would need code in the the current event of your form as well as whatever event sends the letter as follows:

Me.OverrideLetterType.Locked = NOT IsNull(DateLetterSent)



0
 
mbizupCommented:
Its very close to what you have written.

In your After Update event:

If NOT IsNull(DateLetterSent) Then
   MsgBox "You can't override a letter type that has already been sent"
    exit sub
End If
' Your After update code follows here

0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Or use Nz:

If Nz(Me.DateLetterSent, "") <> "" Then
  Msgbox "blah"
Else
  '/ Your AU code
End If
0
 
Dale LoganConsultantAuthor Commented:
You know you're good when you can answer a question that requires you to read the submitter's mind. I do want to UNDO the combo box's update. Perfect. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.