Hi Blake,
Its hard to know what you might be doing wrong without know what you are doing. What code have you put in the BeforePrint event, and what code do you have in the userform's cancel button Click event? In your cancel button Click event you should be setting a global variable (one that is declared as Public in a macro module) to indicate you want to cancel printing. Then in your BeforePrint event you should set the Cancel argument to this variable.
Damon
Damon,
i tried what you suggested, the assumtions you made were correct, but once i get out side of the beforeprint macro nothing seems to stop it from printing, im not sure if its because its a "private sub" instead of "sub" proceedure. When i made cancel a global variable it didnt work. the code kinda looks like this
public cancel
Private Sub Workbook_BeforePrint(cancel As Boolean)
'there are a bunch of if statements
userform1.show
end sub
Private Sub CommandButton2_Click() 'which is the cancel button
userform1.hide
cancel=true
end sub
thanks again for your help.
Blake
Hi Blake,
Private Sub Workbook_BeforePrint(Cancel As Boolean)
"your code & if your if statements find an error"
Cancel = True
End Sub
Jim ,
Blake,
Yes, that information helps. Here's what you should do:
1. Add the statment
Public CancelPrint As Boolean
to the top of a macro module (NOT part of the userform or workbook event code). This makes this variable visible to both the userform code and the BeforePrint event code.
2. Set the CancelPrint variable in the CommandButton2 Click event:
Private Sub CommandButton2_Click() 'which is the cancel button
unload userform1
CancelPrint=true
end sub
3. Setup your BeforePrint event:
Private Sub Workbook_BeforePrint(cancel As Boolean)
'there are a bunch of if statements
CancelPrint = False
'will set CancelPrint to True if user clicks Cancel Print button
userform1.show
'Set cancel True or False depending on value of CencelPrint
Cancel = CancelPrint
end sub
Note that you don't have to Hide the userform to make the cancel work--so I recomment simply unloading it since the CancelPrint variable does the work. That way each time you do a print the userform would re-load.
Happy computing.
Damon