Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    64

    Unanswered: Print Report With Only Current Record From Form

    I have a form where sales reps enter
    1- Customer details (Page 1 of Form; "Contacts")
    2- Order details (Page 2 of Form; "Orders" which is a subform in Contacts form)
    3- Call details (Another form; "Calls")

    What I need to do is this:
    After a Salesrep places a call to a customer and makes a sale, I want them to be able to print a "Report" page of ONLY the "Current" record, and include some of the fields I choose from the 3 forms I mentioned above.

    Thanks for your help.

  2. #2
    Join Date
    Jan 2004
    Posts
    64

    What am I doing wrong?

    This is what I tried, it doesn't work. What am I doing wrong?

    I created the report from a query I wrote which gets the selected fields I need from these tables.

    I used the code below on the "On Open" event of the report. Is the code correct but should not be in "On Open" event, or is the code wrong?

    Private Sub Report_Open(Cancel As Integer)
    Dim strDocName As String
    Dim strWhere As String
    strDocName = "rpt_Subscription_Form"
    strWhere = "[ContactID]=" & Me!ContactID
    DoCmd.OpenReport strDocName, acPreview, , strWhere
    End Sub


    (Note: ContactID is the key field in Contacts table).

    Am I completely on the wrong track?

  3. #3
    Join Date
    Dec 2003
    Location
    Toronto, Ont. Canada
    Posts
    238

    Re: What am I doing wrong?

    Originally posted by bsarman
    This is what I tried, it doesn't work. What am I doing wrong?

    I created the report from a query I wrote which gets the selected fields I need from these tables.

    I used the code below on the "On Open" event of the report. Is the code correct but should not be in "On Open" event, or is the code wrong?

    Private Sub Report_Open(Cancel As Integer)
    Dim strDocName As String
    Dim strWhere As String
    strDocName = "rpt_Subscription_Form"
    strWhere = "[ContactID]=" & Me!ContactID
    DoCmd.OpenReport strDocName, acPreview, , strWhere
    End Sub


    (Note: ContactID is the key field in Contacts table).

    Am I completely on the wrong track?
    Thanks for the extra information! I was trying to write a reply to you earlier but it was getting extremely long since I didn't know any of your fields, relationships, key fields, control names, etc... I decided I'd write it up after work at home... lol... This makes it much simpler!!

    You are definitely not on the wrong track! That's a great start...

    The problem is that you are trying to open the report AGAIN within it's own Open event... You have two choices...

    1) Place the code you've got there behind the On Click event of a button on the form that the user will click to open the report...
    This way you will be opening the report with the Where criteria intact...

    Or

    2) Set the Filter property of the report as it opens... ie in the On Open event... (change "frmContacts" to your form name... and make sure that [ContactID] is the name of the Control on your form)

    Me.Filter = Forms!frmContacts![ContactID]
    Me.FilterOn = True

    You can't use Me to refer to the form in the report On Open event, because at this point Me is the report itself...

    HTH somewhat...

  4. #4
    Join Date
    Jan 2004
    Posts
    64
    Thanks for your help.
    This is working just fine now. My mistake was to try to do this in the report when I should have done it in the main form itself.

    I created a button that opened the report (that derived from the query) and on the On Open event of this button I put this code:

    Private Sub Command148_Click()
    Dim strDocName As String
    Dim strWhere As String
    strDocName = "qry_Subscription_Form"
    strWhere = "[ContactID]=" & Me!ContactID
    DoCmd.OpenReport strDocName, acPreview, , strWhere

    End Sub

    I appreciate your taking the time to offer help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •