Hide query results

pds8475

Registered User.
Local time
Today, 23:52
Joined
Apr 26, 2015
Messages
84
Hi
I have a button on a form which is used to print shipping labels.
This button runs a Query and then a report using the code 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.OpenQuery "PrintLabelQuery"
DoCmd.OpenReport "Labels", acViewPreview
 DoCmd.PrintOut , , , , 1
DoCmd.SetWarnings True
End Sub

But I need both the query results and the report to not be seen. All I want to happen when clicking the button is that a label is printed.

Any Help would be most appreciated
 
Right I have both the report and query closing after the print command using the code below.
Code:
 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.OpenQuery "PrintLabelQuery"
DoCmd.OpenReport "Labels", acViewPreview
 DoCmd.PrintOut , , , , 1
DoCmd.Close acReport, "Labels"
DoCmd.Close acQuery, "PrintLabelQuery"
 DoCmd.SetWarnings True
End Sub
But this is far from perfect as this means that both the query and report flash up on screen.
is there a better way of doing this so both of them are not seen at all?
 
I would have thought you should be using acViewNormal is you don't want to see the report.
Preview does what it says on the tin.

Not sure about the query, sorry, but I'd probably base the report on the query.?
 
Thanks Gasman that sorted the report. I tried doing the same on the query but that didn't work. There must be a way to have the query run in the background. And yes the report is based on the query.
 
Ahh I found out that I don't need to open the query to run it as the report is based on the query so opening the report automatically runs the query.
All I needed was the following code.

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.SetWarnings True
End Sub

So thanks again Gasman. Without your help I would just been going round in circles.
 
Glad I was able to help. :D

Ahh I found out that I don't need to open the query to run it as the report is based on the query so opening the report automatically runs the query.
All I needed was the following code.

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.SetWarnings True
End Sub

So thanks again Gasman. Without your help I would just been going round in circles.
 

Users who are viewing this thread

Back
Top Bottom