Results 1 to 8 of 8
  1. #1
    benks is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    12

    How to run a report for only the current record

    Hi guys,



    My database is set up as such:

    Main Form, Sub Form1 (Priorities), Sub Form2 (Strats), Sub Form3 (Tasks)

    They are linked as you would expect: Main Forum PK = Sub Form1 FK, Sub Form1 PK = Sub Form2 FK, Sub Form2 PK = Sub Form3FK

    I have a report that runs values for Sub Form1, 2 and 3. Right now when I run the report, it runs for all records from the Main form. How do I set up a "Print Report" button to only print the report for the specific record that I am on in the Main form. For example, if I am currently on record 5 of the main form, all I would want to print is all priorities (and by extension strats and tasks) that related to record 5. If I were to move to record 7, I would only print priorities, strats and tasks that related to record 7, etc. I also need this to run via a button for ease of use to the end user.

    Thanks for any help

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    As answered elsewhere:

    One way, with the appropriate form reference:

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

  3. #3
    benks is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    12
    Thanks for both response, haha.

    I am new with VBA and having a bit of trouble getting the code right, if you don't mind helping me out it would be greatly appreciated. This is what I have entered thus far and I can't seem to get it to work. This would be a "on click" from a button.

    Code:
    DoCmd.OpenReport "HSIF data table", , , "ID Prime = " & Me.Text1088

    HSIF data table - name of the report
    ID Prime - text box in the report i want to screen by
    Text1088 - control in my main form that contains the ID prime number I wish to screen by

    Thanks

    Edit: I have also tried both text and numeric (adding the '). The data is numeric, but it is going into a text box. Dunno if that could be causing my problem
    Last edited by benks; 06-04-2013 at 05:08 PM. Reason: More info

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Because of the inadvisable space, the field name needs brackets.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    benks is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    12
    So i tried adding brackets and it didn't work. I also renamed the fields all of the names to single words to avoid any issues with spaces but the code still won't work. It currently looks as such:

    Code:
     DoCmd.OpenReport "HSIFdatatable", , , "IDPrime = " & Me.Text1088
    Thanks in advance

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Looks okay. Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    benks is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    12
    Here it is. Command button is in the form HSIF Data Entry Form, report options tab. Report isn't formatted yet, but I doubt that is the issue.

    Edit: I solved the issue, ended up adding AcViewPreview to the line code and it worked great. Thanks a ton for your help
    Last edited by benks; 06-04-2013 at 07:32 PM. Reason: Privacy

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Glad you sorted it out. Without that it should have been going straight to the default printer, but properly filtered.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Email a report of the current record.
    By jonudden in forum Reports
    Replies: 4
    Last Post: 08-21-2023, 07:37 AM
  2. Print Report from Current Record
    By hnkford in forum Reports
    Replies: 15
    Last Post: 05-22-2015, 08:08 AM
  3. Report using current DAO record data
    By normever in forum Reports
    Replies: 1
    Last Post: 03-20-2013, 09:38 PM
  4. Print current record to a report
    By drawc in forum Access
    Replies: 2
    Last Post: 01-15-2012, 12:48 AM
  5. Report from current record
    By billgyrotech in forum Reports
    Replies: 18
    Last Post: 07-26-2011, 03:39 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