Linking a report to a form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joseppi01
    New Member
    • Nov 2011
    • 7

    Linking a report to a form?

    Hi there

    I don't have a lot of programming experience (apart from google searching everything and a bit in Crystal) but Access just throws me!

    I'm trying to link a record from a report to the same record in the form.
    I have been looking in multiple forums trying to find a fix and can't seem to duplicate it correctly.

    The most recent one I've tried is:

    Code:
    Private Sub Description_Click()
    
     Dim EntityName As String
     Dim Docname As String
     
     Docname = "frmDelivery Details"
     Filtername = "qryDelivery Details"
     
     strWhere = "[frmDelivery Details].[DD_ID] = 'Me.DD_ID'"
     DoCmd.OpenForm Docname, acNormal, Filtername, strWhere
     
    End Sub
    Which asks for frmDelivery Details.DD_ID parameter value, then returns a Run-time error 2501

    Both the form and the report are based on qryDelivery Details. Does that need to be linked in somehow?

    I have attached the database (apologies if there are any other bad practices in there...)and would be very appreciative of any help!
    Attached Files
    Last edited by zmbd; Aug 27 '13, 02:23 AM. Reason: [z{please format code/sql/etc.. using the [CODE/] fomat button}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Lets start by correcting Line 9:
    strWhere = "[frmDelivery Details].[DD_ID] = 'Me.DD_ID'"
    It is malformed.
    If you will place:
    debug.print strWhere
    Immediately after Line 9, run the code, press <ctrl><g> in the window that opens you more than likely will see:
    "[frmDelivery Details].[DD_ID] = 'Me.DD_ID'" instead of the desired:
    "[frmDelivery Details].[DD_ID] = 'ControlValue_S tr'"


    Change Lets start by correcting Line 9:
    strWhere = "[Field from your Recordset here] = '" & Me.DD_ID & "'"

    -- This suposes that Me.DD_ID is a text/string.
    If it is numeric and the field it refers to is set numeric then remove the single quotes
    If it is a Date/time then replace the single quotes with the hash ( " # " )

    -- [Edit{We also need to correct "[frmDelivery Details].[DD_ID] should be changed to reflect the desired field in your record set...post#4}]


    Also, please understand, we do not normally open un-requested attachments. A practical example as to why can be found in a most recent post. This unfourtunate Member open a file from a trusted source and is now haveing all sorts of issues! http://bytes.com/topic/access/answer...ll-ms-products
    Last edited by zmbd; Aug 28 '13, 11:42 AM. Reason: [z{added the further correction to code from Post4}]

    Comment

    • joseppi01
      New Member
      • Nov 2011
      • 7

      #3
      My apologies, I won't attached unless requested in future.

      I've tried to fix as you've explained and it is still asking for parameters?

      It now reads:
      Code:
      Private Sub Description_Click()
      
       Dim EntityName As String
       Dim Docname As String
       
       Docname = "frmDelivery Details"
       
       strWhere = "[frmDelivery Details].[DD_ID] = " & Me.DD_ID & ""
       Debug.Print strWhere
       DoCmd.OpenForm Docname, acNormal, , strWhere
       
      End Sub
      The DD_ID is a primary key from the original table, which holds the main delivery details information.
      Last edited by zmbd; Aug 27 '13, 03:31 AM. Reason: [z{please remember to format your code with the [Code/] button :) }]

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        silly me....
        I missed another error in the code:
        strWhere = "[frmDelivery Details].[DD_ID] = " & Me.DD_ID & ""

        "[frmDelivery Details].[DD_ID]" needs to refer to the field in your record set not to the field on your form.

        Why don't you take a look at the following document and see how parameter queries work with reports. It works thru a simple example...
        Using parameters with queries and reports
        The method here hasn't changed since v97/2003 thru to v2010.
        If you get stuck on something there, post back and we'll get it cleared up.
        Once again, sorry I missed that other issue. :(

        Comment

        • joseppi01
          New Member
          • Nov 2011
          • 7

          #5
          You are a lifesaver! It's all working now.

          Thank you so much for all your help!!

          Comment

          Working...