Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24

    Button to run report off Primary Key

    Hello,

    My Access knowledge and coding knowledge is limited so please bare with me.

    I have created an access database that has two tables

    Customers
    Primary Key = Customer ID

    Contracts
    Primary Key = Contract ID



    I've created simple forms for both just by highlighting and going to create form. I've Also set the relationship properly for a One (customers) to Many (contracts). As well as a report that pulls information from both Customers Table and Contracts Table. The report (the report is a contracts) is designed as a simply way to print out / save to pdf. But when I open the report all of the (contracts) for all records in the Contracts Table comes up.


    What I would like to do is add a button to the Contracts Form that allows me to run the report (contracts) with the criteria of the current record that the form is on. I Imagine this would have to be pulled up by the Primary Key on the contracts table.

    If this is possible and somebody would be able to give me instructions on how to do this It would be greatly Appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is this what you're after?

    BaldyWeb wherecondition
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24

    Unfortunately Not

    That is not what I am looking to do...
    I'm Looking to be able to automatically populate the report from the forms current record.

    For Instance:
    I'm on contracts form on record 116 of 282. Where the contract ID is 187.
    I want to be able to click a button that opens a report populated with the information from Contract ID 187.

  4. #4
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24

    Continued

    Quote Originally Posted by tdanko128 View Post
    That is not what I am looking to do...
    I'm Looking to be able to automatically populate the report from the forms current record.

    For Instance:
    I'm on contracts form on record 116 of 282. Where the contract ID is 187.
    I want to be able to click a button that opens a report populated with the information from Contract ID 187.
    I want that same button to perform this operation for any record i'm on so say if I'm on contracts form on record 147of 282. Where the contract ID is 196. I want to be able to click a button that opens a report populated with the information from Contract ID 196.

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Then it is what you want. As the link mentions, the same technique works with OpenReport.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24

    Sorry

    Quote Originally Posted by pbaldy View Post
    Then it is what you want. As the link mentions, the same technique works with OpenReport.
    Sorry... I will Try and report back... Thanks.

  7. #7
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24
    Where do I enter this code?

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That is VBA code; presumably you'd want it behind the button you mentioned. If this is your first code:

    http://www.baldyweb.com/FirstVBA.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24
    hmmm... I am Getting this error

    Run-time error '424':

    Object Required




    Here is what I Currently Have:

    Private Sub Command47_Click()
    DoCmd.OpenReport "contract by all", , , "Contract ID = " & Contracts.Command47
    End Sub

    contract by all is the report I want to run... Contract ID is the primary field of contracts table and contracts.Command47 is the button control

    Sorry to be such a pain. I am very new to this and all help is greatly appreciated.

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try this:

    DoCmd.OpenReport "contract by all", acViewPreview, , "Contract ID = " & Me.Command47

    I switched it to preview for testing; you can have it go directly to printer if you want.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24
    Ok this is exactly what I have:

    Private Sub Command51_Click()
    DoCmd.OpenReport "contract by all", acViewPreview, , "Contract ID = " & Me.Command51
    End Sub

    It is giving me this error code. :
    Run-time error '438': Object doesn't support this property or method access 2007

    I googled the error and a lot of people said that it was caused by not having a windows update... however my windows is fully up to date.

    Any Suggestions would be greatly appreciated.

  12. #12
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24

    Ok So I Chose an alternate route that Will Suffice.

    It is slightly more work on the end user but for some reason I can't get the code to work.. So here is what I did
    I created a query and in the criteria area of Contract ID I Put [Please Enter Contract Id] then I Created my report based off of that query. Then Just put an open report button linked to the new report.
    How do I set this to solved?
    Thank you very much for all you help. Though I was not able to accomplish what I was trying to do your help helped me accomplish other goals using the vba codes.

  13. #13
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Does the report open without error if you open it directly? Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    tdanko128 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2011
    Posts
    24

    Yes and No

    When I used this code I could get the report to open but their was no data in the form:

    DoCmd.OpenReport "contract by all", acViewPreview, , _
    "[Contract ID]=Forms!Contracts

    When I used the code from this thread nothing would come up except the error. As far as the data base posting. I'm not 100% sure about what that means. The database would still work.

  15. #15
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'm not sure what you mean by "the database would still work". You're saying this code doesn't work, are you not? It is sometimes easier to figure out why something isn't working when you can play with it yourself.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2010, 01:32 PM
  2. Button to open a Report
    By 95DSM in forum Reports
    Replies: 1
    Last Post: 07-09-2010, 11:11 AM
  3. Send Primary Key from a Form To A Report
    By nkuebelbeck in forum Forms
    Replies: 1
    Last Post: 03-18-2010, 12:24 PM
  4. Error in Print Report Button
    By Robert M in forum Reports
    Replies: 16
    Last Post: 09-23-2009, 03:08 PM
  5. Replies: 1
    Last Post: 04-06-2009, 12:05 PM

Tags for this Thread

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