More Issues

csdrex87

Registered User.
Local time
Yesterday, 22:13
Joined
Jul 1, 2009
Messages
66
I have created a custom menu bar that checks for duplicates via before update. This menubar attempts to bypass it however when i close the form and try to open another it keeps giving me the error you cannot modify a new report while another is already being processed.

here is my code:

Private Sub SaveWeekly_Click()
Dim iEmpId As Long

If IsNull(Me.Emp_ID) Then

If (MsgBox("Please enter your Employee ID " & vbCrLf & _
vbCrLf & "Please enter a different date.", _
vbOKOnly, "Duplicate Employee") = vbOKOnly) Then
Cancel = True
End If

End If

If IsNull(Me.[Month/Wk]) Then

If (MsgBox("Are you sure you wish to leave without inputting
information?", vbQuestion + vbYesNo, _
"Confirmation") = vbYes) Then
DoCmd.Close acForm, "EmployeeWeekly"
*****HERE IS WHERE I WANT TO OPEN MENUBAR********
Else:
Cancel = True
End If

Else:
iEmpId = DCount("[Emp_ID]", "tblEmployeeWeekly", "[Emp_ID] =
" & Me.Emp_ID & " And [Month/Wk]='" & Me.[Month/Wk] & "'")

If iEmpId <> 0 Then

If (MsgBox("An entry for this date already exists. " & vbCrLf
& _ vbCrLf & "Please enter a different date.", _
vbOKOnly, "Duplicate Employee") = vbOKOnly) Then
Cancel = True
End If

Else:
DoCmd.Save acForm, "EmployeeWeekly"
DoCmd.OpenForm "EmployeeWeekly"
End If

End If
End Sub
 
I think you have your code in the wrong event.

You are using:
Code:
Private Sub SaveWeekly_Click()

...
Cancel = True   ' not valid in the event
...

The problem is this event can not be canceled this way. I would urge you to try the Before Update Event which can be canceled with your code.

Code:
Private Sub Form_BeforeUpdate([b]Cancel As Integer[/b])

...
[b]Cancel[/b] = True   ' is valid in the event
...


End Sub


I would also urge you to use:

Code:
Option Explicit

at the top of every VBA module. There is an option to always add this. If you do, then I bet you get lots of compiler error due to variable not defined (DIM ...). This will make your life a lot easier if you will use it.
 

Users who are viewing this thread

Back
Top Bottom