Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jan 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Table with only the last record (Access 2000)

    I need to copy the tables orders and orderdetails containng only the last order.I am copying them to another database using the formula
    DoCmd.CopyObject db.Name, "orders", acTable, "orders"
    DoCmd.CopyObject db.Name, "orderdetails", acTable, "orderdetails"
    I want to use the criteria (SELECT Max([orderid]) FROM orders) in order to send the tables with only the last order,but i do not know how to build the code.Can you help me ?
    I guess that i should build a make table query that contains only the last order.To this end i have tried to build the following function:
    Public Function Alan()
    Dim SQL As String
    SQL = "SELECT * INTO orders1 FROM orders WHERE orders1.orderid = DMax(orderid,orders)"
    CurrentDb.Execute SQL
    End Function
    However i get the error "too few parameters".Where am i wrong and i can i do in that way ?

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Table with only the last record (Access 2000)

    Your SQL is
    SQL = "SELECT * INTO orders1 FROM orders WHERE orders1.orderid = DMax(orderid,orders)"
    Try this instead
    SQL = "SELECT * INTO orders1 FROM orders WHERE orders.orderid = DMax('orderid','orders')"
    or
    SQL = "SELECT * INTO orders1 FROM orders WHERE orders.orderid = (SELECT Max(orderid) FROM orders)"

  3. #3
    Lounger
    Join Date
    Jan 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank you !

    Thank you, Pat ! I tried it and i succeeded.So thank you so much for your great help

    kind regards
    Canett

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •