print report based on query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JohnHo
    New Member
    • Feb 2009
    • 12

    print report based on query

    why won't this work?

    I have a form which has a text box: forms!frmCaseLo g!tboCaseID the RecordSource for the form is tblCaseLog with the field [lngCaseID]

    I would like to print a report with details entered into the form.

    For the report RecordSource I have created a query "qryCurrentCase Info" which has in the criteria for [lngCaseID] the control above on the form "frmCaseLog "

    I have a command button [cmdPrint] to print the report with the code

    Code:
    Private Sub cmdPrint_Click()
    
    Dim stDocName As String
    
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 
       
    With Forms!frmUrgentTriage1 
       
        .tbo2CaseID.SetFocus 
        .tbo2CaseID.Requery 
        .Repaint 
    
    End With
    
    
    
        stDocName = "Report1"
        DoCmd.OpenReport stDocName, acNormal
    
    End Sub
    If I debug.print the control I get the Case ID value but I cannot get the query to use the Case ID value as the criterion for the report.

    what gives? am I missing something?

    thanks a bunch!

    /jh
  • PianoMan64
    Recognized Expert Contributor
    • Jan 2008
    • 374

    #2
    Originally posted by JohnHo
    why won't this work?

    I have a form which has a text box: forms!frmCaseLo g!tboCaseID the RecordSource for the form is tblCaseLog with the field [lngCaseID]

    I would like to print a report with details entered into the form.

    For the report RecordSource I have created a query "qryCurrentCase Info" which has in the criteria for [lngCaseID] the control above on the form "frmCaseLog "

    I have a command button [cmdPrint] to print the report with the code

    Code:
    Private Sub cmdPrint_Click()
    
    Dim stDocName As String
    
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 
       
    With Forms!frmUrgentTriage1 
       
        .tbo2CaseID.SetFocus 
        .tbo2CaseID.Requery 
        .Repaint 
    
    End With
    
    
    
        stDocName = "Report1"
        DoCmd.OpenReport stDocName, acNormal
    
    End Sub
    If I debug.print the control I get the Case ID value but I cannot get the query to use the Case ID value as the criterion for the report.

    what gives? am I missing something?

    thanks a bunch!

    /jh
    Hey JohnHo,

    You simply need to add the following to your Docmd.OpenRepor t settings.



    Code:
    'OLD WAY
    DoCmd.OpenReport stDocName, acNormal 
    
    'NEW WAY
    
    DoCmd.OpenReport stDocName, acNormal,,"[tboCaseID]=" & me.lngCaseID
    The last Option if you read the help file for OpenReport, has an option to pass it a query string if you want something limited by a value in a certain field.

    Hope that helps,

    Joe P.

    Comment

    Working...