Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your issue is that you cannot use aliases (e.g. [serial number left]) in the order by - you have to use the original expression, or the original field names.

    You might find it a lot easier if you wrote a function to generate the numeric version (it could be similar to the one I posted above). You would avoid all the nested IIf's and it could work with any length serial number string. It would also make the query more manageable.



    Note: Cint will fail with any number over 32767 - use CLng instead.

  2. #17
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    As John_G suggested, write a function to extract the numeric portions, then incorporate that function in the query. It really simplifies the query.
    Put the query in a module so that it call be called from anywhere. I don't know what all the [serial number left] and [serial number right] selections were about, I just started at the left end and plowed thru to the end at the right.

    Code:
    'Serial number extract
    Public Function snExt(S_N As String) As Long
        Dim i As Long
        For i = 1 To Len(S_N)
            If IsNumeric(Mid(S_N, i, 1)) Then
                snExt = snExt & Mid(S_N, i, 1)
            End If
        Next
        snExt = CLng(snExt)
    End Function
    SELECT MASTER.[MFR MDL CODE], snExt(Master.[Serial Number]) as [Serial Number Whole], MASTER.[SERIAL NUMBER] , TCDS_Data.CODE
    FROM MASTER LEFT JOIN TCDS_Data ON MASTER.[MFR MDL CODE] = TCDS_Data.CODE
    WHERE (((MASTER.[MFR MDL CODE]) = '1151410'))
    ORDER BY snExt(Master.[Serial Number]);

  3. #18
    Join Date
    Aug 2017
    Posts
    8
    Well, it's done. I coded up the Serial function (read: I copied and pasted the Serial function). I had to change the result to Double from Long because I was getting an overflow error (I'm not sure that I understand why since my longest serial number is twelve digits and Long is supposed to handle up to eighteen or nineteen). I also had to incorporate the Nz function to handle the empty serial number fields. With those mods to the function and the function calls, the query is finally giving the correct results!!

    Thanks davegri, John_G, and orange ... you guys are the best.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 05-17-2016, 06:04 PM
  2. Replies: 3
    Last Post: 11-09-2015, 10:32 AM
  3. Retrieving records according to criteria
    By jruizmesa in forum Forms
    Replies: 2
    Last Post: 03-24-2012, 11:43 AM
  4. Replies: 9
    Last Post: 06-26-2011, 09:14 PM
  5. Replies: 2
    Last Post: 03-31-2009, 11:15 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