Code in wrong event

Experts,
The following code does work for my combo box:
Private Sub StoreID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblDesignatedEmployee", "[StoreID]= " & Me.StoreID) > 0 Then
   Beep
   MsgBox "This Store already has assigned employees. If you need to modify exisiting employees return to Maintenance and select Modify Designated Employee"
   Cancel = True
   Exit Sub
End If
 
End Sub

Open in new window

After I close the message I immediately click on the command button Close. Here's the code:
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click


    If Me.Dirty Then
    Me.Undo
    End If
    DoCmd.Close
    DoCmd.OpenForm "frmMaintenance"
Exit_cmdClose_Click:
    Exit Sub

Err_cmdClose_Click:
    MsgBox Err.Description
    Resume Exit_cmdClose_Click
    
End Sub

Open in new window


Here's my problem. I get the same message I got from my combo box "This Store already has assigned employees. If you need to modify exisiting employees return to Maintenance and select Modify Designated Employee" and cannot close. Do I have my code for the combo box Before_Update event in the wrong event?
Frank FreeseAsked:
Who is Participating?
 
mbizupConnect With a Mentor Commented:
Try placing the following in your before update event after the message box:

Me.StoreID.undo
0
 
Rey Obrero (Capricorn1)Commented:
try clearing the combo box with

Private Sub StoreID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblDesignatedEmployee", "[StoreID]= " & Me.StoreID) > 0 Then
   Beep
   MsgBox "This Store already has assigned employees. If you need to modify exisiting employees return to Maintenance and select Modify Designated Employee"
   Cancel = True

   me.StoreID=""  '< add this line
   exit sub

end if

end sub
0
 
Frank FreeseAuthor Commented:
capricorn: I tried that before and got this error:
Run-time error '-2147352567 (8002000090'

The macro or function set to the BeforeUpdate or ValidationRule property for this field is prevent Monthly Bonus from saving Data in the field.

However, mbizup suggestion did appear to work so I'll accept that. Thanks capricorn
0
 
Frank FreeseAuthor Commented:
thank you
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.