ADO method for getting highest ID #

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using ADO to query an ms Access db. How do I get the highest number in
the first field: ID which is the primary key, and return it to Excel?
 
I have an open connection and have dumped rs1 to excel. Now I want the max id

I'm getting and error with this

'''' GET THE MAX ID
Dim rs2 As New ADODB.Connection
sql = "Select Max(ID)" & sTable
Debug.Print sql
rs2.Open sql, cn
Sheets("ADO").Range("MaxID").CopyFromRecordset rs2


Here's the Immediate window results for both rs's

Select ID, Lname, Fname, Address, DOB, Street, City, State FROM EMPLOYEES
WHERE (((ID)>0) AND ((Lname)Like's%')) ORDER BY ID

Select Max(ID) FROM EMPLOYEES

The error occurs on the rs2.Open

Any suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top