[AccessD] Open Report from MainForm based on SubForm

Hollis, Virginia hollisvj at pgdp.usec.com
Wed Oct 14 07:44:15 CDT 2009


I have a command button on the main form that I want to open a report
filtered to one record based on a value on the SubForm.

 

frm_VehicleInspection (mainform)

frm_VehicleInspectionSub (subform)

rpt_VehicleInspection (report to open)

VehicleInspectionID is the key to open the report.

 

****************

On Error GoTo Err_cmdPrint_Click

    

    Dim stDocName As String

    Dim stLinkCriteria As String

    

'If
IsNull(Forms!frm_VehicleInspection.frm_VehicleInspectionSub!VehicleID)
Then

 '       MsgBox "You must must enter a record before printing.",
vbExclamation + vbOKOnly, "Entry Required"

  '    Exit Sub

'End If

 '   vbresponse = acDataErrContinue

'    DoCmd.RunCommand acCmdSaveRecord

    stDocName = "rpt_VehicleInspection"

 

    Forms![frm_VehicleInspection]![frm_VehicleInspectionSub].SetFocus

   

This didn't work (it opens the report, but shows all the records on the
report): 'DoCmd.OpenReport stDocName, acPreview, ,
"Forms![frm_VehicleInspection]![frm_VehicleInspectionSub].Form![VehicleI
nspID]=" & 

Forms![frm_VehicleInspection]![frm_VehicleInspectionSub]![VehicleInspID]

 

 This didn't work:   'DoCmd.OpenReport stDocName, acPreview, ,
"Forms![frm_VehicleInspection]![frm_VehicleInspectionSub].Form![VehicleI
nspID]=" & Me![VehicleInspID]

 

This didn't work either:    DoCmd.OpenReport stDocName, acPreview, ,
"Forms![frm_VehicleInspection]![frm_VehicleInspectionSub].Form![VehicleI
nspID]=" & strDocName!VehicleInspID.[VehicleInspID]

 

Exit_cmdPrint_Click:

    Exit Sub

 

Err_cmdPrint_Click:

    MsgBox Err.Description

    Resume Exit_cmdPrint_Click

End Sub

 

Virginia




More information about the AccessD mailing list