Results 1 to 3 of 3
  1. #1
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150

    MS Access VBA - Query String to find Max Alphanumeric Value

    Hi,



    Having trouble with designing a query where the returned value will be the maximum of an alphanumeric string in the format off.

    ID (short text)
    1234X - Where I need to select the max ID, where the first 4 chars are number and the last character may be a letter.


    Example of return results:
    1021
    1022
    1023
    1023A
    1023B

    Max = 1023


    Thanks for any help.

    Regards

  2. #2
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    SOLVED:

    Turns out using DMax function works find in my case.

    Awesome.
    Easy fix.


    Thanks

  3. #3
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Update:

    DMax encounted a problem when the digits increased.

    DMax worked fine for....

    Code:
    ID    (note:  this datatype is short text)
    1001
    1001A
    1002
    1003
    1004
    1004A
    1004B
    
    DMax = "1004B" (note: use a left or right function in VBA to trim to just "1004")
    However, when the table was....


    Code:
    ID
    50000  (Note: For some reason Access puts the largest numerical data type at the top of the table - even a simple sort query does not fix this)
    1001
    1002
    1003
    1004
    1004A
    1004B
    
    DMax = "1004B" (This is a problem)
    So, i remedied the issue with creating a query with two fields. The first field is, of course, ID, the second field is an expression which converts the ID to just the numeric portion. The expression is "Sorted: Val([ID])".

    So, the query datasheet looks like...

    Code:
    ID                          Sorted
    50000                   50000   (this value is STILL at the top regardless of sorting my ascending order....)
    1001                     1001
    1002                     ....
    1003                     ....
    1004                     ....
    1004A                   1004
    1004B                   1004

    Now that the "sorted" query column/field exists, the DMAX will return as...

    Code:
    DMax = 50000
    As it should!

    A lot of work and messing around for something so simple. .. Hopefully this helps someone. Note: the VAL function will not work for format of A1234, and will only work for 1234A, where the alphabetical characters are the SUFFIX. Val(A1234) will return null or 0.

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

Similar Threads

  1. RegExp to Find String at END of a String
    By Micron in forum Programming
    Replies: 3
    Last Post: 01-17-2018, 09:43 PM
  2. Need Help to find SQL connections string
    By datadc in forum Access
    Replies: 4
    Last Post: 01-16-2017, 08:37 PM
  3. Replies: 2
    Last Post: 08-13-2016, 05:13 PM
  4. Replies: 8
    Last Post: 06-26-2016, 01:39 PM
  5. Update Query - Random Alphanumeric String
    By turkeylord in forum Queries
    Replies: 3
    Last Post: 09-12-2014, 12:55 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