Code is Printing the form and not the report

Rusty

Registered User.
Local time
Today, 10:59
Joined
Apr 15, 2004
Messages
207
Hey Guys,

I have a form with a button that opens a report in preview mode containing data from the form.

I've coded it so a message box then appears asking the user if they want the print the report Yes/No and then export the report Yes/No.

This button/code works on all the other forms in the database (Access 2000) no problem but on this form (with the code below) the export works fine, but if I select "Yes" for the print option, it prints out the form and NOT the report.

Any ideas? I'm using "V" and "L" as the variables in the code for each of the forms, but would it be this that's causing the problem? Any ideas on a solution?

Rusty
:d

Code:
Private Sub btnPrintInvoiceRequest_Click()
On Error GoTo Err_btnPrintInvoiceRequest_Click
    
    DoCmd.OpenReport "rptInvoice Request Form_study charges", acViewPreview, , ""

Dim VResponse As Integer
VResponse = MsgBox("Do you want to print this invoice now?", vbYesNo, "Print Invoice")
If VResponse = vbYes Then
    DoCmd.PrintOut acSelection, 1, 1, , 1
Else
End If

Dim LResponse As Integer
LResponse = MsgBox("Do you want to export the report to Word?", vbYesNo, "Export to Word")

If LResponse = vbYes Then
    DoCmd.OutputTo acOutputReport, "rptInvoice Request Form_study charges", acFormatRTF, , , ""
Else
End If

Exit_btnPrintInvoiceRequest_Click:
    Exit Sub
    
Err_btnPrintInvoiceRequest_Click:
        Resume Exit_btnPrintInvoiceRequest_Click

End Sub
 
Make sure that the form is not pop-up or Modal.
 
Hey Fizzio,

Thanks for the reply - I tried that but the form is not set as either modal or popup. I'm at a loss as to what is going on here as the other forms are the same in design and coding and they seem to work fine.

Rusty
:D
 
Well I figured it out after looking at a backup of the database that I had made a few weeks back.

The form in question has an OnTimer event running every second - therefore the form has the focus if you like and and not the report. Therefore when the printing is run by the code it prints the selection, i.e. the form and NOT the report.

All fixed now (I got rid of the OnTimer event). Phew...such a rookie mistake!! :p

Rusty
:D
 

Users who are viewing this thread

Back
Top Bottom