Results 1 to 7 of 7
  1. #1
    Maxjoo is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2024
    Location
    Carmel, Indiana, USA
    Posts
    18

    Post How to preview a report of a single record using a command button in form?


    I do not remember to have asked this before...

    I have a form showing records for a particular building. I added a command button to show the record I have on the screen, using a report; but when I click on the command button, the report shows ALL the records in the DB. How can I make the report to show the current record? I know I have to use a macro (or a similar instruction) or the "On Current" property, but HOW? THANK YOU IN ADVANCE!!!!!...

  2. #2
    Jamesy_007 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    109
    Quote Originally Posted by Maxjoo View Post
    I do not remember to have asked this before...

    I have a form showing records for a particular building. I added a command button to show the record I have on the screen, using a report; but when I click on the command button, the report shows ALL the records in the DB. How can I make the report to show the current record? I know I have to use a macro (or a similar instruction) or the "On Current" property, but HOW? THANK YOU IN ADVANCE!!!!!...
    Hi Maxjoo,

    To get pass this issue, you have to place a criteria on the ID field within the RowSource property of the report....

    As an expression it will look something like this

    Code:
    [Forms]![theFormName]![ID]
    This expression will select the exact record you are on and will generate the report you want....


    Regards

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Or you can use the wherecondition argument of OpenReport:

    https://www.baldyweb.com/wherecondition.htm

    It would be more flexible than what was suggested, which is also somewhat incomplete.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Maxjoo is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2024
    Location
    Carmel, Indiana, USA
    Posts
    18
    Quote Originally Posted by Jamesy_007 View Post
    Hi Maxjoo,

    To get pass this issue, you have to place a criteria on the ID field within the RowSource property of the report....

    As an expression it will look something like this

    Code:
    [Forms]![theFormName]![ID]
    This expression will select the exact record you are on and will generate the report you want....


    Regards
    I am doing something wrong because I am not getting the results I want...

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I would also use the WHERE option of the OpenReport command.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  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,652
    The method I suspect jamesy was going for was not described for a rookie to follow. They were likely leading you towards using a criteria in the report's source query. That would work, but is less flexible.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by Maxjoo View Post
    I am doing something wrong because I am not getting the results I want...
    When in doubt, Google for the syntax and how to use the command.

    https://learn.microsoft.com/en-us/of...cmd.openreport

    https://www.google.com/search?q=docm...hrome&ie=UTF-8
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 3
    Last Post: 08-22-2024, 02:36 PM
  2. Print Preview Command Button Locks Access
    By DanKoz in forum Access
    Replies: 7
    Last Post: 03-19-2018, 12:34 PM
  3. Print Preview Command Button on Report
    By HeadBanger in forum Reports
    Replies: 2
    Last Post: 03-18-2018, 11:23 PM
  4. Replies: 6
    Last Post: 12-30-2014, 10:05 PM
  5. Replies: 4
    Last Post: 06-27-2014, 08:02 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