Results 1 to 10 of 10
  1. #1
    OFA is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    6

    Printing a single report from form


    Hello,

    I am having a problem linking a button on my form to print a single report of the entry that I just entered on the form. I have created the button and it links properly to the report however when I click the button the report comes up blank. For some reason it seems that the fields are not linked properly between the form and the report? When I open up the report manually all the report appear to be there and does not encounter the same problem, all the information is displayed. Below is the code I used for the button:

    Code:
    Private Sub cmdPrint_Click()
    Dim strReport As String
    Dim strWhere As String
    
    If Me.Dirty Then Me.Dirty = False   'save the record
    
    strReport = "Renewal Plan Checklist"
    strWhere = "[Plan #] = " & Me![Plan #]
    
    DoCmd.OpenReport strReport, acPreview, , strWhere
    
    End Sub
    Thanks in advance!

  2. #2
    Join Date
    May 2010
    Posts
    339
    Quote Originally Posted by OFA View Post
    Hello,

    I am having a problem linking a button on my form to print a single report of the entry that I just entered on the form. I have created the button and it links properly to the report however when I click the button the report comes up blank. For some reason it seems that the fields are not linked properly between the form and the report? When I open up the report manually all the report appear to be there and does not encounter the same problem, all the information is displayed. Below is the code I used for the button:
    Code:
    Private Sub cmdPrint_Click()
    Dim strReport As String
    Dim strWhere As String
     
    If Me.Dirty Then Me.Dirty = False   'save the record
     
    strReport = "Renewal Plan Checklist"
    strWhere = "[Plan #] = " & Me![Plan #]
     
    DoCmd.OpenReport strReport, acPreview, , strWhere
     
    End Sub



    The spaces in the field names are going to be problems, also your ID should be used (PK)


    Code:
     Dim strWhere As String
        If Me.Dirty Then    'Save any edits.
            Me.Dirty = False
        End If
        If Me.NewRecord Then 'Check there is a record to print
            MsgBox "Select a record to print"
        Else
            strWhere = "[YourID] = " & Me.[YourID]
            DoCmd.OpenReport "Renewal Plan Checklist", acPreview, , strWhere 
     
            Me.Requery
        End If

  3. #3
    OFA is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    6
    Hmm...I put the code in that you suggested and now a little box comes up when I press the button. It doesn't matter if I put anything in the box or just click ok with it blank but the report that comes up is still blank and not filled in.

  4. #4
    Join Date
    May 2010
    Posts
    339
    Quote Originally Posted by OFA View Post
    Hmm...I put the code in that you suggested and now a little box comes up when I press the button. It doesn't matter if I put anything in the box or just click ok with it blank but the report that comes up is still blank and not filled in.
    What did you put between the brackets?

    Code:
    strWhere = "[YourID] = " & Me.[YourID]

  5. #5
    OFA is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    6
    I changed the "Your ID" to "Plan #" which is the primary key

  6. #6
    Join Date
    May 2010
    Posts
    339
    This basic code works, I know for a fact I use it myself. Two things I don't like about your primary key. You have a space in it and second you use the # sign. If your in the building stages of this I would makes some minor changes. I will try and reporduce your primary key and see if i can get it to work.

  7. #7
    OFA is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    6
    That's true, unfortunately though i'm not in the building stages but I suppose I can still go and change everything which references "Plan #" to something like "PlanNo". What I don't understand is I have the exact same button on another form with the exact same code (from original post) and it works and with that button the primary key is Tracking # so for some reason it works for that and not Plan #...odd

  8. #8
    Join Date
    May 2010
    Posts
    339
    Hi OFA,

    can you post your fields names.



    Richard

  9. #9
    OFA is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    6
    Sorry for the late response, I was away from a computer for the weekend. I assume you meant the list of field names for the form? The're listed below:

    Plan #
    Received on
    ASSOC
    Last Site Visit
    MFPA Name
    MFPA #
    Review Form
    NAME1
    NAME2
    ADDR1
    ADDR2
    ADDR3
    CITY
    PC
    Application
    EMAIL
    Send Info
    Approval Form
    CL#
    Area Verification
    MPAC Notice
    Other
    Application Form
    Report
    Map 4
    Map Roll#
    Map Boundaries
    Map eligible areas
    Map structures
    Entered by
    Comments

    I was also told that the person working on the database before me in the office deleted some code by mistake on the form, is there any general codes that a form should have which may have been deleted that could prevent this from working?

  10. #10
    OFA is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    6
    Problem has been resolved, thanks for the help!

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

Similar Threads

  1. Expand entire row not just single cell in a Report
    By CityOfKalamazoo in forum Reports
    Replies: 2
    Last Post: 07-28-2016, 09:22 AM
  2. Printing report from Form
    By cotri in forum Access
    Replies: 8
    Last Post: 05-24-2013, 12:01 PM
  3. Print Single Report
    By emkwan in forum Access
    Replies: 1
    Last Post: 01-29-2010, 11:19 AM
  4. Report Printing
    By newtoAccess in forum Reports
    Replies: 5
    Last Post: 12-02-2009, 07:46 PM
  5. Replies: 16
    Last Post: 06-03-2009, 07:01 AM

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