Results 1 to 5 of 5
  1. #1
    BudMan is offline Novice
    Windows 11 Office 365
    Join Date
    Nov 2014
    Location
    Stem, NC USA
    Posts
    23

    Question Prompt for a value to look up or return the largest value if no number is entered

    I have a table where I keep track of my home inspections.


    The fields include ID (Auto Number)
    Insp_Num (The number is generated using the DMAX function)
    Insp_Date
    Name
    Address
    Notes


    I am trying to craft a query that prompts an Insp_Num to look up or display the largest number in the field if I do not enter a number at the prompt, along with the other fields.


    I have tried Googling but cannot find what I am looking for. Is it ever possible?

  2. #2
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    prompts an Insp_Num to look up or display the largest number in the field if I do not enter a number at the prompt

    The only way I can think of doing it is with a button, so on a FORM. (Nobody should have direct access to your tables anyway!) Then you'd do something like prompt the user for an Inspection Number (just use a combobox). Then you can run one query if the combobox has a value selected and another if it doesn't.

    If all you want is the most recent record, I suppose you could do something like

    SELECT TOP (1) Insp_Num
    FROM InspectionsTable
    ORDER BY InspectionDate DESC;

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Query prompts are annoying and I don't use. There is no validation of input and then have to deal with case of no input. I use VBA to construct filter/sort criteria and apply to form or report.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    mostly, I will want to do this on a Form and use the Form's textbox as criteria,
    but for query, you add Parameter to it so it will prompt you.
    if nothing is inputted use the max value of the field.
    this query will prompt for the Inspection Number or non is inputted, the max will return:
    Code:
    SELECT InspectionTable.Insp_Num, InspectionTable.Insp_Date, InspectionTable.Name, InspectionTable.Address
    FROM InspectionTable 
    WHERE InspectionTable.Insp_Num=IIf(IsNull([Enter Inspection Number]),DMax("Insp_Num","InspectionTable"),[Enter Inspection Number]);

  5. #5
    BudMan is offline Novice
    Windows 11 Office 365
    Join Date
    Nov 2014
    Location
    Stem, NC USA
    Posts
    23
    Thanks jojowhite. That worked exactly like I wanted it to.

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

Similar Threads

  1. Replies: 1
    Last Post: 06-18-2022, 04:53 PM
  2. Replies: 7
    Last Post: 12-05-2018, 02:00 PM
  3. Replies: 3
    Last Post: 08-31-2015, 09:04 AM
  4. Replies: 1
    Last Post: 11-13-2012, 05:03 PM
  5. Query to find the second largest year
    By hawkins in forum Queries
    Replies: 2
    Last Post: 07-05-2011, 11:17 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