Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default 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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default 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?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default 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?




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Next highest Value Thanks Excel Worksheet Functions 1 January 20th 09 09:39 PM
Please post this thread a correct full method, method about Nast Runsome New Users to Excel 8 February 25th 08 03:29 PM
Please post this thread a complete correct method, method about te Nast Runsome New Users to Excel 0 February 23rd 08 09:42 PM
Display the Highest, Second Highest, Third Highest and so on... gkb Excel Discussion (Misc queries) 7 December 1st 06 10:45 PM
2 rows, highest No in row 1, then highest number in row 2 relating to that column, possible duplicates John Excel Worksheet Functions 3 August 11th 06 04:34 AM


All times are GMT +1. The time now is 02:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"