Problem printing

pds8475

Registered User.
Local time
Today, 17:48
Joined
Apr 26, 2015
Messages
84
Hi

Im using a button to print a report based on a text box values on the form.

the code for which is below
Code:
 Private Sub SaveBtn_Click()
 DoCmd.SetWarnings False
DoCmd.RunSQL "Update BookInTable SET DateBookedOut = '" & Me!DateTxt & "'  WHERE BarCode ='" & Me![BarTxt] & "'"
DoCmd.RunSQL "Update BookInTable SET BookedOut = True  WHERE BarCode ='" & Me![BarTxt] & "'"
DoCmd.OpenReport "Labels", acViewNormal
 DoCmd.PrintOut , , , , 1
DoCmd.Close acReport, "Labels", acSaveNo
DoCmd.SetWarnings True
 End Sub

The problem that I am getting is not only is the label printing but so is the form.
Any ideas why this would be?
 
What is the recordsource of report "Labels"?

You sql could be condensed to 1 line (I think)
Code:
DoCmd.RunSQL "Update BookInTable SET DateBookedOut = '" & Me!DateTxt & "' , BookedOut = True  WHERE BarCode ='" & Me![BarTxt] & "'"

You may have an issue with field DateBookedOut -- DATE datatypes should be enclosed in "#".
 
The form is printing because it has focus. You can use DoCmd.SelectObject to make your report the active object before calling the PrintOut command.
 
Never mind found out what it was.
The line of code

Code:
DoCmd.OpenReport "Labels", acViewNormal

Sends the report to the printer and closes the report

So the line

Code:
 DoCmd.PrintOut , , , , 1

prints the form instead

While this line doesn't error even though the report is already closed.it also does nothing

Code:
DoCmd.Close acReport, "Labels", acSaveNo
 

Users who are viewing this thread

Back
Top Bottom