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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Increment Field Using VB?

Status
Not open for further replies.
Oct 27, 2009
30
US
Good day, all,
I have created a query based on an Access Database. I would like to add a numeric field to the query results that automatically increments each item in the results list. Result 1 would have value of 1, result 2 value of 2, etc. It has to be an "automated" solution, meaning that copy and paste, etc., won't be an acceptable solution. Any ideas as to how to best do that? I'm wondering if VB loop is the way to go (if so...suggestions on exactly how to implement would be most appreciated).
Thanks in advance.
 
I'm not sure I understand your question...It's a query created in an access database...SQL...
 



You originally said, "based in an Access databse." That does not tell me WHERE you are programming.

Asked, you stated, "in an Access database."

That tells me that MS Access is the application.

Code:
SELECT A.Col1, (Select Count(*) From TableName Where Col1<A.Col1)+1
FROM TableName A
Order By A.Col1
as an example.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Again, I am likely being obtuse, but I have only two columns to work with in the table. One is date, the other is ID. One ID may have many dates. Each ID/Date Listing needs a unique number. In this scenario, which column is Col1?
 


Which ever column you sort on.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top