Open Report based on Txt Box Value

T

TeeSee

I would like to have a cmdButton on my main form that when clicked
opens a report. The button will reside on the main form and I would
like to pass the current PK Autonumber value directly to a simple
query on the query grid to set the criterion for the report.
My query grid design currently gives me what I want in output. Any
thoughts would be appreciated.
 
F

fredg

I would like to have a cmdButton on my main form that when clicked
opens a report. The button will reside on the main form and I would
like to pass the current PK Autonumber value directly to a simple
query on the query grid to set the criterion for the report.
My query grid design currently gives me what I want in output. Any
thoughts would be appreciated.

Make the query the Report's Record source.
Do NOT filter the records in the query.
Open the report using the OpenReport method and use the method's Where
argument to filter the report records.

DoCmd.OpenReport "ReportName",acPreview, , "[ID]= " & Me.[ID]

Change [ID] to whatever the actual PrimeKey Autonumber field name is.
 
T

TeeSee

From what you say here, your report is based on a query. Your current PK
Autonumber field should be a field in that query. Put the following
expression in the criteria of that field:
Forms!NameOfYourMainForm!NameOfYourPKField.

The code for the command button's click event should be:
DoCmd.OpenReport

Steve
(e-mail address removed)






- Show quoted text -

Thank you both for solution(s) that do exactly as I planned. I had
guessed the WHERE approach but wasn't sure just how ... but would
never have thought about the Forms! ..... approach. Very interesting.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top