?
Solved

Code in wrong event

Posted on 2011-10-20
4
Medium Priority
?
164 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:Frank Freese
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 36999610
Try placing the following in your before update event after the message box:

Me.StoreID.undo
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36999616
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
 

Author Comment

by:Frank Freese
ID: 36999697
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
 

Author Closing Comment

by:Frank Freese
ID: 36999702
thank you
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

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

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

830 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