Results 1 to 7 of 7
  1. #1
    craigperkins is offline Novice
    Windows 11 Access 2003
    Join Date
    Aug 2023
    Posts
    5

    How to get Query Criteria to pull the ID of the record automatically when running a report,

    I have a report that pulls information from a query on my main database a report of booking information, however we have to type in the ID number to pull the report.

    Query criteria being [Enter ID Number] which comes up when you hit the report button.



    I would like the report to automatically pull the ID number when we hit run report.

    Can anyone help?

    Below is current Event Command, Thanks

    Private Sub Command734_Click()
    On Error GoTo Err_Command734_Click

    Dim stDocName As String

    stDocName = "Confirmation Hotel Email WPD"
    DoCmd.OpenReport stDocName, acPreview

    Exit_Command734_Click:
    Exit Sub

    Err_Command734_Click:
    MsgBox Err.Description
    Resume Exit_Command734_Click

    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Where are you meant to get the ID from?
    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

  3. #3
    craigperkins is offline Novice
    Windows 11 Access 2003
    Join Date
    Aug 2023
    Posts
    5
    So the ID is a field within the database, our booking number.
    I get the feeling I need to put something in the "on Click" and in the query but I am lost.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by craigperkins View Post
    So the ID is a field within the database, our booking number.
    I get the feeling I need to put something in the "on Click" and in the query but I am lost.
    Yes, the ID would be a field in the database, that will likely contain many records and hence many values.
    How are you intending to identify the one that you want out of all of those records?
    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

  5. #5
    craigperkins is offline Novice
    Windows 11 Access 2003
    Join Date
    Aug 2023
    Posts
    5
    When you are on that specific record form you then hit the button to run the report.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Ok, then the Where condition would be along the lines of

    Code:
    "ID = " & Me.BookingNumber
    where ID is the field name, and BookingNumber the control name.

    If the bookingnumber is actually text, then surround that with '

    Microsoft always has documentation of it's products, though in this case they only show the filter parameter, not the Where parameter.

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

    Plenty of videos also on YouTube on Access

    https://www.youtube.com/watch?v=I3AQVZCEHmI
    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

  7. #7
    craigperkins is offline Novice
    Windows 11 Access 2003
    Join Date
    Aug 2023
    Posts
    5
    Fixes - you are a star....... Thanks a million.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-17-2023, 08:17 AM
  2. Replies: 2
    Last Post: 09-25-2020, 10:39 AM
  3. Replies: 13
    Last Post: 08-08-2013, 04:52 PM
  4. Replies: 4
    Last Post: 03-11-2012, 08:51 AM
  5. Help Automatically running and Update Query
    By JohnRandolphSTL in forum Queries
    Replies: 8
    Last Post: 04-13-2010, 02:08 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