Printing a Report from the Current Record on a Sub-Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Redbeard
    New Member
    • Oct 2007
    • 112

    Printing a Report from the Current Record on a Sub-Form

    I am working with Access 2007. I am trying to print a report from the current record on a Subform. My form is comprised of a Main form with a sub-form and another sub-form with in the sub-form.
    Main form = Renters Info
    Subform = Rental Info
    Subform = Dates for rental

    I want to print off a report for one rental that lists the info for the rental with the renter information. I have created a button on the Rental subform to print the report. I have tried various codes that I have found on the internet to connect the current record to the report, however it does not work. I keep getting a pop-up box that asks me to “Enter Parameter Value” for the FuntionID. If I enter the right ID it works(wrong Id I get an error), but I don’t want to have to enter the ID as it should just print the current record without asking?
    Here are the three codes I have been working with. All with the same result.
    Code:
    Dim strDocName As String
    Dim strWhere As String
        strDocName = "Contract"
        strWhere = "[FunctionID]=" & Me!FunctionID
        DoCmd.OpenReport strDocName, acPreview, , strWhere
    End Sub
    
    Dim strReportName As String
       Dim strCriteria As String
        
       strReportName = "Contract"
       strCriteria = "[FunctionID]=" & Me![FunctionID] & ""
       DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
        
    End Sub
    
    Dim Condition As String
        Condition = "[FunctionID]=[Forms]![Main]![SubFunctionForm].[Form]![FunctionID])"
        DoCmd.OpenReport "Contract", acViewPreview, , Condition
    
    End Sub
    I am not sure what I am doing wrong but think it is probably something to do with the printing for a subform? Any Ideas?

    Thanks
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32634

    #2
    You have two end subs with no start subs. End subs can possibly be omitted but the start subs are nearly always critical.

    Comment

    • Redbeard
      New Member
      • Oct 2007
      • 112

      #3
      To cleairify, these are the three different codes I have tryed and got the same result.
      Code:
      Private Sub Print_Contract_Click()
      Dim strWhere As String
          strDocName = "Contract"
          strWhere = "[FunctionID]=" & Me!FunctionID
          DoCmd.OpenReport strDocName, acPreview, , strWhere
      End Sub
      Code:
      Private Sub Print_Contract_Click()
      Dim strReportName As String
      Dim strCriteria As String
       
          strReportName = "Contract"
          strCriteria = "[FunctionID]=" & Me![FunctionID] & ""
          DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
       
      End Sub
      Code:
      Private Sub Print_Contract_Click()
      Dim Condition As String
           Condition = "[FunctionID]=[Forms]![Main]![SubFunctionForm].[Form]![FunctionID])"
           DoCmd.OpenReport "Contract", acViewPreview, , Condition
       
      End Sub

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32634

        #4
        If the reporting of the error is correct then the problem is in your query. The field is probably mis-spelled as [FuntionID]. If that's not it then you need to be more careful with your posts as we can only work with what you post.

        Certainly, without errors elsewhere, I would expect your first code example to work assuming the value of [FuntionID] is numeric.

        Comment

        • Redbeard
          New Member
          • Oct 2007
          • 112

          #5
          I found the problem... It was a bad link between my report and sub-report. Somehow it got linked directly to my table and not to the report itself. Thank for the suggestion of looking in the query, it let me back to the report where the error was.

          Many Thanks NeoPa

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32634

            #6
            I think I may have helped accidentally then. Not that I wasn't trying to, of course. Just that the help was more of a by-product of the suggestion than the suggestion itself. Never mind. Any help is helpful at the end of the day ;-)

            Comment

            Working...