Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Ado add an id variable to a table

Hello,

I'm creating a recordset with the following (partial) code:


rs1 = MainTableRangeSheet & "$" & MainTableRangeNoDollar & "]"
Sql = "SELECT * FROM " & rs1 & " AS T1
objRecordset.Open Sql, ObjConnection, adOpenForwardOnly

The code works fine...

I'm interested at adding a unique ID variable to each record (1,2,3...)

Could you help?

Thanks
Avi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Ado add an id variable to a table

Hello,

I'm creating a recordset with the following (partial) code:


rs1 = MainTableRangeSheet & "$" & MainTableRangeNoDollar & "]"
Sql = "SELECT * FROM " & rs1 & " AS T1
objRecordset.Open Sql, ObjConnection, adOpenForwardOnly

The code works fine...

I'm interested at adding a unique ID variable to each record
(1,2,3...)

Could you help?

Thanks
Avi


Assuming row1 contains fieldnames, and records start in row2, and colA
is empty...

In A2 type =Row()-1 and copy down to last record. Then do a
Copy/PasteValues so your unique IDs don't get screwed up when you
add/remove records. Of course, you can always [re]set this at any time
by assigning a formula with VBA...

With Range("A2:A" & lLastRow)
.Formula = "=Row()-1":.Value = .Value
End With

...where you've already determined the row number of the last record in
the tabe.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
two-way variable table keeps repeating same value Damon G. Excel Worksheet Functions 6 April 2nd 23 07:11 PM
Lookup data in a variable table & retrieve data from a pivot table Shawna Excel Worksheet Functions 3 October 10th 08 11:11 PM
one variable data table alexasanford Excel Worksheet Functions 2 March 8th 07 06:57 AM
having a table name be a variable trav Excel Discussion (Misc queries) 1 April 11th 06 12:36 AM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


All times are GMT +1. The time now is 08:29 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"