Results 1 to 3 of 3
  1. #1
    zprozio is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    2

    How do I set a default value based upon the max value returned by parameterized query?

    In my database, I have a table called "Rules." The Rules table holds all rules for the organization across an undetermined number of departments. The unique identifier in each of my tables is specified in a field I call IDNo which is generated as an autonumber. In my Rules Table, there are a number of additional fields, two of which are "Department" (which references the IDNo from the "Departments" table and is pulled using the Lookup feature) and "Rule_Number" which is a field of datatype number. The Rule_Number field does not contain a unique value; however, when used together the Department and Rule_Number fields will comprise unique values. That is, there will be exactly 1 Rule_Number 1 for each department, 1 Rule_Number 2 for each department, etc.

    I want to automatically populate the Rule_Number field with a calculated default value using the next number in order when I run a parameterized query of the following form:



    Code:
    SELECT 1 + Max([Rules].Rule_Number) AS MaxOfRule_Number 
    FROM [Rules]
    HAVING (((Max([Rules].Department))=[Department?])
    My question is how do I use the Default Value parameter in my Rules Table to reference this code? I cannot seem to do it using the Expression Builder.

    Thank you in advance for any guidance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Use code in some event to populate field.

    Generating sequential and/or unique identifier is a common topic.

    Rule_Number = DMax("Rule_Number", "Rules", "Department=" & Department) + 1

    Is this a multi-user database? Either commit record to table immediately or generate the number at end of data entry in BeforeUpdate event.
    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.

  3. #3
    zprozio is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    2
    Awesome! Thank you!

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

Similar Threads

  1. Replies: 1
    Last Post: 06-01-2017, 09:29 AM
  2. How to use parameterized query
    By kumar_3345 in forum Access
    Replies: 2
    Last Post: 06-28-2014, 09:05 AM
  3. Open Dynamic Parameterized Query using DAO
    By ItsMe in forum Programming
    Replies: 17
    Last Post: 04-06-2014, 10:57 AM
  4. Filter form with parameterized query
    By wnicole in forum Access
    Replies: 3
    Last Post: 10-03-2013, 12:33 PM
  5. Form with parameterized query
    By ngruson in forum Forms
    Replies: 3
    Last Post: 08-11-2010, 11:08 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