Report data from Form

  • Thread starter Thread starter Scott B
  • Start date Start date
S

Scott B

Greetings,

I have a form that derives data from a query. I have a report that mirrors
the form so I can print the data. I would like a command button on the
form that would print or preview a report for the same reocrd that is
currently on the form. I donot know how to word the command button VB to
accoplish this.

Thanks for the help.

Scott B
 
Look in the code in the Button's Click event. You should find a
DoCmd.OpenReport. Put the cursor in OpenReport, and click F1 for Help. You
are going to use the WhereCondition argument.

If the unique ID for the record is a field called DataID, is a text field,
and is in TextBox txtID on the form, then the DoCmd.OpenReport will look
something like the following (air code):

DoCmd.OpenReport "rptA",,,"[DataID]="""&Me.txtID&""""

If it's a numeric field, it should read

DoCmd.OpenReport "rptA",,,"[DataID]=" & txtID

Larry Linson
Microsoft Access MVP
 
Scott said:
I have a form that derives data from a query. I have a report that mirrors
the form so I can print the data. I would like a command button on the
form that would print or preview a report for the same reocrd that is
currently on the form. I donot know how to word the command button VB to
accoplish this.


Modify the wizard generated code to look like:

stDoc = "nameofreport"
stCriteria = "keyfield = " & Me.keyfield
DoCmd.OpenReport stDoc, acViewPreview, , stCriteria
be sure to replac nameofreport and keyfield with the names
you are actually using.
 
Back
Top