Opening a report from a form, printing, then closing

smelly

Registered User.
Local time
Today, 21:52
Joined
May 23, 2002
Messages
44
I have a form where I am trying to open a report from a check box. The form has a sample ID and I am trying to run the report from the query for this sample ID. How can I pass this to the report so the report opens for this sample ID then prints, then closes.
Thanks!
 
Put a where clause on the OpenReport statement:

WHERE SampleID = Me!SampleID

That will display the correct record on the report. I'm not sure if you want open the report for display, print, or both. The mode of the report is one of the arguments of the OpenReport statement, if you wanted to do both you could have an OpenReport statement for each mode. How long do you want it to display to the screen? You can always open for display and then print from the display screen if it looks good.

HTH
 
Thanks! I am getting a compile error now.

Private Sub checkbox1_Click()
DoCmd.OpenReport "InternalLab1b", acViewPreview
SELECT *
FROM Query1b
WHERE [Sample ID] = Forms!ChainOfCustody!BBCID
End Sub
 
The word WHERE is used only in an SQL statement.

In the OpenReport method the criteria is put in double quotes without the word WHERE.

Try this:-

Private Sub checkbox1_Click()
DoCmd.OpenReport "InternalLab1b", acViewPreview, , "[Sample ID] = Forms!ChainOfCustody!BBCID"
End Sub
 
Thank you for the help. It prompts me with this "Forms!ChainOfCustody!BBCID". Is there a way to just pass it in, WIthout being prompted to enter it?
Thank you.
 
You are being prompted because Access can't find Forms!ChainOfCustody!BBCID.

Are you sure that is the name of the control, no typos, only one exists?
 
Try this:-

Private Sub checkbox1_Click()

DoCmd.OpenReport "InternalLab1b", acViewPreview, , "[Sample ID] = " & Forms!ChainOfCustody!BBCID

End Sub

This will open it up for preview, if you want to just print it, use acViewNormal
 
Last edited:

Users who are viewing this thread

Back
Top Bottom