Results 1 to 5 of 5
  1. #1
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295

    Locating last item in a field

    Good Day All.

    I have a table "Invoices" with a field "ID", which I want to open and find the last number in the "ID" field.



    This is my code:

    HTML Code:
    Function CreateInvoice(OrderID As Long, Amt As Currency, InvoiceID As Long, OrigAmt As Currency _
    , Vat As Currency, Reference As String, Deposit As Currency) As Boolean
        Dim rsw As New RecordsetWrapper
          
         rsw.OpenRecordset ("Invoices")
           
        MsgBox rsw.[ID]
    End Function
    can anyone assist?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    I have never seen RecordsetWrapper.

    rsw.OpenRecordset ("SELECT * FROM Invoices ORDER BY ID;")
    rsw.MoveLast

    Or use DMax() instead of recordset object.

    MsgBox DMax("ID", "Invoices")
    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
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Thanks VIP for that swift response to my problem.

    It works just fine and is very simple. However when I changed the field name "ID" in the table to "Invoice ID" it wouldn't work. it give an error message "syntax error, missing operator in query expression 'Max(invoice ID)' ".
    Does this mean I cannot use multi-word field names in the tables?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    Advise not to use spaces or punctuation/special characters (underscore only exception) in names nor reserved words as names. If you do, must enclose in [ ].

    Max([invoice ID])

    Better would be InvoiceID or Invoice_ID.
    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.

  5. #5
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Thanks. It works well.

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

Similar Threads

  1. Replies: 8
    Last Post: 10-27-2016, 06:24 AM
  2. Locating Clarksville Ice Cream.xlsx file
    By Lou_Reed in forum Access
    Replies: 4
    Last Post: 05-05-2016, 05:13 PM
  3. Replies: 7
    Last Post: 11-29-2015, 07:24 AM
  4. Replies: 8
    Last Post: 01-30-2014, 01:43 PM
  5. Help locating a record on click
    By cvclubs in forum Access
    Replies: 5
    Last Post: 10-18-2011, 07:54 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