Report From Form Information

C

Chip Melton

I am wanting to place a button on a form to print a report using one of the
fields of the form to be a critera of the query used by the report. Let me
show an example:

I have a form that shows inpection data including the inspection # of that
inspection. So i want to populate the form and then hit the button and
print a report of the the Inspection # showing on the form. How can i do
that?

I am relatively new to VB, so be gentle... THANKS in Advance!!!
 
J

James

Under "Filter" on the properties menu for the inspection report put:
([InspectionID]= Forms![frmInspection]![InspectionID])

Where InspectionID is the Inspection number field name and frmInspection is
the name of the form that you are wanting to populate.

Then under "On Click" on the properties menu. Click on the right side where
the ... button is and select Code Builder. Then ad this text:

Private Sub btnInspection_Click() ' btnInspection is the name of the
button.
On Error GoTo Err_btnInspection_Click
If IsNull(Me![InspectionID]) Then
MsgBox "There must be report first'." ' This is where your
error message goes.
Else
Dim stDocName As String

stDocName = "reportInspection" ' The name of the report goes
here.
DoCmd.OpenReport stDocName, acViewPreview
End If

Exit_btnInspection_Click:
Exit Sub

Err_btnInspection_Click:
MsgBox Err.Description
Resume Exit_btnInspection_Click

End Sub

GTH
James
 

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