Results 1 to 8 of 8
  1. #1
    jlclark4 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Dec 2010
    Location
    North Carolina
    Posts
    155

    Create a Report from a entry on form using command button.

    I am trying to run a report for a current record. Lets say this form has 3 records in it. I want to be able to click the command button (code below) on record 2 and the report opens up to that page. Right now, its opening it from the beginning. What do I need to do?



    Code:
    Private Sub Command864_Click()
    On Error GoTo Err_Command864_Click
        Dim stDocName As String
        stDocName = "rptCDSCursoryReview3"
        DoCmd.OpenReport stDocName, acPreview
    Exit_Command864_Click:
        Exit Sub
    Err_Command864_Click:
        MsgBox Err.Description
        Resume Exit_Command864_Click
     
    End Sub

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    do you have a key field in records?
    DoCmd.OpenReport stDocName, acPreview,, "keyfield='" & keyfield & "'"

  3. #3
    jlclark4 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Dec 2010
    Location
    North Carolina
    Posts
    155
    Do you mean matching fields between form and report? Name, Numbers etc match but I think it would be easiest to assign autonumber entry numbers.

    So lets say I want the Entry Number (Auto Number) to match the Entry Number (Auto Number) in the report.

    Would it be:
    DoCmd.OpenReport stDocName, acPreview,, "EntryNumber='" & EntryNumber & "'"

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    almost, but it should be:
    DoCmd.OpenReport stDocName, acPreview,, "EntryNumber=" & EntryNumber

    because entryNumber is a number, you don't need the single quot (') around.

  5. #5
    jlclark4 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Dec 2010
    Location
    North Carolina
    Posts
    155
    It gave me a error. I added a entry number field to the table and added it to the form and report. Field name: EntryNumber
    Its telling me along with highlighting the last EntryNumber "variable not defined"
    Code:
    Private Sub Command864_Click()
    On Error GoTo Err_Command864_Click
        Dim stDocName As String
        stDocName = "rptCDSCursoryReview3"
        DoCmd.OpenReport stDocName, acPreview, , "EntryNumber=" & EntryNumber
     
    Exit_Command864_Click:
        Exit Sub
    Err_Command864_Click:
        MsgBox Err.Description
        Resume Exit_Command864_Click
     
    End Sub

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I think you just created a new textbox in you form and set control source to entrynumber, did you rename the textbox to "entrynumber"?

    by the way, entrynumber must be a number field.

  7. #7
    jlclark4 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Dec 2010
    Location
    North Carolina
    Posts
    155
    Ok, I did catch where I never renamed the text box in the form. Now both text boxes match names and the command button works again BUT it is still bringing me to the first page of the report and not the selected record. Also, number works the same as autonumber correct?

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Yes, number works the same as autonumber.

    you said you have a command button for each record, right? then maybe you can check the "allow filter" property in report design view to see if it's "YES".

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  2. How to create and print unique report for each entry???
    By Stelios Panayides in forum Reports
    Replies: 2
    Last Post: 10-05-2009, 08:54 AM
  3. Form/report command button code
    By max3 in forum Forms
    Replies: 1
    Last Post: 08-26-2009, 02:18 AM
  4. Adding Command Button To Form
    By uneek78 in forum Forms
    Replies: 7
    Last Post: 03-27-2009, 07:43 PM
  5. Create a command button to Browes for file
    By sawill in forum Programming
    Replies: 3
    Last Post: 03-15-2009, 05:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums