Open Report based on Txt Box Value

  • Thread starter Thread starter TeeSee
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top