ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ADO method for getting highest ID # (https://www.excelbanter.com/excel-programming/321965-ado-method-getting-highest-id.html)

gocush[_29_]

ADO method for getting highest ID #
 
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?


Rob van Gelder[_4_]

ADO method for getting highest ID #
 
The SQL is:
select max(id) from my_table;

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"gocush" /delete wrote in message
...
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?




gocush[_29_]

ADO method for getting highest ID #
 
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?


"Rob van Gelder" wrote:

The SQL is:
select max(id) from my_table;

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"gocush" /delete wrote in message
...
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?





gocush[_29_]

ADO method for getting highest ID #
 
sorry I got it:

Dim rs As New ADODB.Recordset

"Rob van Gelder" wrote:

The SQL is:
select max(id) from my_table;

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"gocush" /delete wrote in message
...
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?






All times are GMT +1. The time now is 10:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com