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

Counter instead of autonumber field

Status
Not open for further replies.

hnunez4399

Programmer
Apr 10, 2003
62
US
How can I create a query / or some type of counter that will populate a field based on its order imported. Essentially, it would be like an autonumber, but I want to be able to reset the number to 1 when needed, and within access I only know of doing this by compacting the database.

Any help would be appreciated.
Thx,
 
No essentially I import an excel file that contains the following fields

sku
SumOfUnits
Cat
StyleDescription

This gets appened to a table that contains those fields plus an anutonumber field called "recnum"

Currently it is an autonumber field and if the database has been compacted the first record will be 1 but if not the number will not be 1. I want this field to always reset to 1 all the time / or when the file is imported, that the first record being imported is always 1 and increments by one.....

Let me know if this makes sense.
 
Before the import (VBA code):
DoCmd.RunSQL "ALTER TABLE yourTable ALTER COLUMN recnum COUNTER(1,1)"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I have never written VBA code.
Where would I put this. Sorry still learning.
 
Before the import (SQL code):
ALTER TABLE yourTable ALTER COLUMN recnum COUNTER(1,1);

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Have you followed the following steps?

create a new query, switch to SQL view, paste the SQL code above and run the query.

If not, what did you try that didn't work?


Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
I got it to work.
Thanks for your help I really appreciate it.

Are there any books you recommend that teach you how to program in access?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top