On Fri, 10 Sep 2004 02:29:50 GMT, Dave Elliott wrote:
See my comments intespersed below and also at the bottom..
Here is all my code for the form to make it not close without printing
the
check after a payee has been entered.(Customers)
'On Click Event of Command Button to close form
On Error GoTo Err_Command126_Click
DoCmd.Close
If you use Close you should specify close what.
If intPrint = 0 And IsNull([Customers]) Then
MsgBox "Check(s) Must Be Printed"
Cancel = True
End If
The above 4 lines do not belong in this event. They belong in the
Unload event.
Also, the Command Button Click event does not have Cancel as an
argument, so Cancel = True has no meaning in this context.
Forms!frmAutoPayrollReport.Visible = True
Exit_Command126_Click:
Exit Sub
Err_Command126_Click:
If you cancel the close event, you will generate an error 2501, so you
should trap it here.
MsgBox Err.Description
Resume Exit_Command126_Click
'On Click Event of Print Checks Command Button
Dim intPrinted As Integer
The Dim IntPrint as Integer declaration must go at the very top of the
code sheet, not in an event.
On Error GoTo Err_Command89_Click
Dim stDocName As String
If IsNull(Me.ChkNo) Then
MsgBox "Check Number Needed Please.", vbOKOnly + vbInformation
Exit Sub
End If
stDocName = "Checks"
Forms!blankchecks.Visible = False
DoCmd.OpenReport stDocName, acNormal
intPrinted = 1
Forms!blankchecks.Visible = True
Exit_Command89_Click:
Exit Sub
Err_Command89_Click:
MsgBox Err.Description
Resume Exit_Command89_Click
'On Current Event of Form
intPrinted = 0
'On Unload Event of Form
If intPrint = 0 And IsNull([Customers]) Then
Upon re-reading your original post I realize you want to not close if
[Customers] Is Not Null. My mistake.
MsgBox "Check(s)Must Be Printed"
Cancel = True
End If
I have a form named BlankChecks that I need to make sure that the user
does
not close the form without printing the check.
The form has a Customers field that cant be null, it should key on
this,
if there is a payee(i.e. Customer) then it has to be printed.
It also has a command close button and a command print button on it.
How can i not allow them to close the form if a payee has been entered
in
the control (Customers) and they have not printed the check?
Command button for printing is named Command113 and Command button for
Close is named Command2128
Thanks,
Dave
Here's a working code:
Note.... The lines marked with a ' ** have been changed from yours
Option Explicit
Option Comapare Database
Dim intPrinted As Integer ' **
' The above 3 lines belong at the very top of the report's code sheet,
' before the first event, NOT in an event.
_______________________________
'On Click Event of Command Button to close form
On Error GoTo Err_Command126_Click
DoCmd.Close, acForm, Me.Name ' **
Forms!frmAutoPayrollReport.Visible = True
Exit_Command126_Click:
Exit Sub
Err_Command126_Click:
If Err = 2501 Then ' **
Else ' **
MsgBox Err.Description
End If ' **
Resume Exit_Command126_Click
_________________________________________
'On Click Event of Print Checks Command Button
On Error GoTo Err_Command89_Click
Dim stDocName As String
If IsNull(Me.ChkNo) Then
MsgBox "Check Number Needed Please.", vbOKOnly + vbInformation
Exit Sub
End If
stDocName = "Checks"
Forms!blankchecks.Visible = False
DoCmd.OpenReport stDocName, acNormal
intPrinted = 1
Forms!blankchecks.Visible = True
Exit_Command89_Click:
Exit Sub
Err_Command89_Click:
MsgBox Err.Description
Resume Exit_Command89_Click
____________________________
'On Current Event of Form
intPrinted = 0
_________________________________
'On Unload Event of Form
If intPrint = 0 And Not IsNull([Customers]) Then ' **
MsgBox "Check(s)Must Be Printed"
Cancel = True
End If
___________________________
Try it now Dave.