Report data from Form

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
 
L

Larry Linson

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
 
M

Marshall Barton

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.
 

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