Code to Print a report

hinser13

Registered User.
Local time
Yesterday, 20:17
Joined
Aug 8, 2010
Messages
75
I am trying to create some code to print several reports.

Currently I have three seperate queries underlying three seperate reports. I use critreria in each qery to create the report "quoteNo" I enter the quote no and the report is created for the client.

I want to be able to create all three reports by only entering the criteria "quoteno" once, not 3 times for each report!

I have tried creating a macro with all three reports, but obviously I have to enter the quote no three times as each query currently requires this.

Can anyone help. Thanks in advance to anybody that has the time to help.

Mark
 
I'm guessing you've employed a parameter query for entering the quoteno? So, you've put something like this in the criteria:

[Enter the quote number]

Is that what you currently have?
 
Yes exactly that! One for each of the 3 queries
 
I would love to be able to print the reports using the current record! instead of entering criteria at all!
 
So you can get rid of that parameter.

You need a command button for opening your report. On the click event of the buttong use the OpenReport method to open the report and in one of the arguments of this method there's a way of filtering the report. So it will look like this:

DoCmd.OpenReport "NameOfReport",,, "[QuoteNoField] = " & Me!QuoteNoField

That will open your report to the quote number entered in that textbox. Substitute the right names in the highlighted text. By the way, is QuoteNo field a Text or Number datatype?

Here's a supporting link:

http://www.baldyweb.com/wherecondition.htm

Same concept.
 
Thank you ver much for your time and guidance, it is much appreciated and most helpful.
 
I am close, but the vital ingredient is missing as they say! This code will open the report, but, shows all the records, it is not filtering to the current record for the form! I am obviously doing something wrong!

Private Sub Command55_Click()
On Error GoTo Err_Command55_Click
Dim stDocName As String
stDocName = "rptWorkSchedule"

stLinkCriteria = "[WorkProgrammingQuoteNo]=" & Me![WorkProgrammingQuoteNo]
DoCmd.OpenReport stDocName, acPreview
Exit_Command55_Click:
Exit Sub
Err_Command55_Click:
MsgBox Err.Description
Resume Exit_Command55_Click

End Sub
 
Please compare your Docmd line with what I wrote.
 
Got it working, Thank you for your persistence, how do I get the report to preview instead of going stright to print?

Private Sub Command57_Click()
On Error GoTo Err_Command55_Click
Dim stDocName As String
stDocName = "rptWorkSchedule"
stLinkCriteria = "[WorkProgrammingQuoteNo]=" & Me![WorkProgrammingQuoteNo]
DoCmd.OpenReport "rptWorkSchedule", , , "[WorkProgrammingQuoteNo] = " & Me!WorkProgrammingQuoteNo
Exit_Command55_Click:
Exit Sub
Err_Command55_Click:
MsgBox Err.Description
Resume Exit_Command55_Click
End Sub
 
Good job!

It shouldn't go straight to print because there's no print command in your code, but I would add this parameter (highlighted in red):

Code:
DoCmd.OpenReport "rptWorkSchedule", [COLOR=Red][B]acPreview[/B][/COLOR], , "[WorkProgrammingQuoteNo] = " & Me!WorkProgrammingQuoteNo
 
Worked perfect!, thankyou for you help today.

Kind Regards

Mark
 

Users who are viewing this thread

Back
Top Bottom