Code trouble for report selection criteria

Real Wally

Registered User.
Local time
Today, 22:27
Joined
Jan 28, 2003
Messages
107
I’m trying to create a report from a cmdButton on a form with 2 subforms.
The main form has the linking filed.

Using the code below I get a pop-up that asks for a criteria value and has the wanted value (the IDnumber in the form) above the input field. If I manually enter that number I get the correct report.
What is wrong with my code below?

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Report"

stLinkCriteria = "[IDnumber]=" & Me![IDnumber] & ""

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
DoCmd.RunCommand acCmdPreviewOnePage

Thanks,

Wally
 
Is ID number a string or a number?

stLinkCriteria = "[IDnumber]=" & Me![IDnumber]

is correct if it's a number
 
Thanks for your advice AncientOne.

I've had a lot of trouble getting this to work but it's fine now. I hadn't realised that I also had to enter criteria in the query that underlies the report. Learned something new again :)

Thanks again,
Wally
 
Print Dialog

When printing a Report I use the Print Dialog Box.

DoCmd.SelectObject acReport, stDocName, True
DoCmd.RunCommand acCmdPrint

is there a way to insert the Criteria in this case like one would with Print Preview?

DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
 
Pat Hartman said:
- no you didn't! There is something wrong with the criteria you were using in the OpenForm method. Look at AncientOne's post again.

Pat, I did notice that AncientOne's code missed some code that I originally had there: & ""
However, that didn't do the trick either.
What I've got now is this:

Dim stDocName As String

stDocName = "rptPatentFamily"
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdPreviewOnePage

with report based on a query that has criteria pointing to a linking field. maybe this can be done with less effort but this works and is a method I (now) understand.

Thanks for your input though.

Wally
 
The difference is that you can also open the report without any filtering or open it from a different form. [/B]


Really? That's worth looking into this option in more details than!
I'll give it a go. Thanks for the advice and explanation.

Wally
 

Users who are viewing this thread

Back
Top Bottom