Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table containing only the last record

Status
Not open for further replies.

canett

Technical User
Jan 22, 2006
18
BG
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 ?
 
In adition to my question,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 ?
 
Thank you.There must be also some other error in my lines, since i get now "syntax error " in the following"
Public Function Alan()
Dim SQL As String
SQL = "SELECT * INTO orders1 FROM orders WHERE orders1.orderid = DMax("orderid","orders")"
CurrentDb.Execute SQL
End Function
 
Try this,
SQL = "SELECT * INTO orders1 FROM orders WHERE orders1.orderid = " & DMax("orderid","orders")
 
Tahn you so much. Thats exactly what i needed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top