Print form before closing...

O

Outatym

I have a form that I need the user to print before they close. The only way
for them to close the form is by clicking the "X" button in the top right
corner of the window.

I have to code set up as:

Private Sub Form_Close()
Dim intResponse As Integer

intResponse = MsgBox("Have you printed the form?", vbYesNoCancel, "Print
Form")
If intResponse = 6 Then
DoCmd.Close
ElseIf intResponse = 7 Then
DoCmd.CancelEvent
DoCmd.PrintOut
DoCmd.Close
ElseIf intResponse = 2 Then
DoCmd.CancelEvent
End If

End Sub

But, apparently you can't print the form once the form has been initiated to
close. I thought that canceling the even would make the form stop from
closing, but apparently I was wrong.

How can i re-code this to make it so when the user closes the form, a
message box will appear and ask if they have printed the form. If so, then
the form closes, if not then the form will print, and if they closed the form
accidentally, the cancel button will cancel the form close event?

Thanks!
 
M

missinglinq via AccessMonster.com

In the properties box for your form set "Close Button" property to NO.

Place a command button on your form and place your code in the button's On
Click event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top