473,378 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to get AutoNumber off Access 2003

Hello

I currently have a Access 2003 database, I am able to add a record to it, and the CustomerID field (which is auto generated by the Database) is correctly filled in by the Database. I am now trying to figure out a way to retreive this number to use it in another Table of the Same Database. Anyone have any examples or resources that I can use to find the best way that I can accomplish this task? Any help/resources that you can provide will be greatly appreciated

Thanks
Nov 16 '05 #1
4 6831
Ed_P:
"Ed_P" <an*******@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
Hello,

I currently have a Access 2003 database, I am able to add a record to it, and the CustomerID field (which is auto generated by the Database) is
correctly filled in by the Database.

Set the Autoincrement value of the DataColumn to -1, set hte
AutoIncrementSeed to 0 and set the AutoIncrement property to True. This way
you'll never have two seperate instances of the app trying to send back the
same value. Then, on update, add a Select query at the end. To See this in
action, configure a DataAdapter using the DataAdapter Configuration wizard
and on the advanced options, check the Refresh DataSet option if it's not
checked. Assuming the wizard can generate the commands, you'll see that it
appends a Select statement at the end of the Update statements and that's
how it gets the value(s) back. You may think it's not efficient firing
another query after update and I won't disagree with you, but that's the
nature of the beast. Also, if you try to manage the Autoincrement values,
and you have a multi user app, you are probably asking for Primary Key
violations b/c they will almost assuredly write over each other (or attempt
to anyway before throwing an exception) unless you want to come up with some
pretty sophisiticated ways to work around it. Using the -1 scneario is
great b/c no other app will every add -1 so the db can always assign a legit
value.

If you have datarelations defined, when you find out the new value from the
db, it will change the negative number value that was added by the
datacolumn's autoincrmement property and update the child records.

Check out http://www.betav.com "Managing an @@Identity crisis" by Bill
vaughn under Articles, MSDN. He's talking about SQL Server but the same
principles apply.

HTH,

Bill

I am now trying to figure out a way to retreive this number to use it in
another Table of the Same Database. Anyone have any examples or resources
that I can use to find the best way that I can accomplish this task? Any
help/resources that you can provide will be greatly appreciated!
Thanks

Nov 16 '05 #2
Here is another method - after the insert, execute the following select
statement, using the same connection:
SELECT @@IDENTITY
or
SELECT @@IDENTITY As TheNewId
It returns the last AutoNumber inserted (works for any table with a
AutoNumber, there are no parameters, etc, it returns the last AutoNumber
generated).

"Ed_P" <an*******@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
Hello,

I currently have a Access 2003 database, I am able to add a record to it, and the CustomerID field (which is auto generated by the Database) is
correctly filled in by the Database. I am now trying to figure out a way
to retreive this number to use it in another Table of the Same Database.
Anyone have any examples or resources that I can use to find the best way
that I can accomplish this task? Any help/resources that you can provide
will be greatly appreciated!
Thanks

Nov 16 '05 #3
Hello Chris

Thanks for the quick reply. I'll try what you mentioned, do you happen to have any sample source code to go along with your suggestion?
Nov 16 '05 #4
Basically it is a simple select, instead of "Select * From MyTable", you do
a
"Select @@IDENTITY As TheNewId", the only difference there is no "From"
clause.
The select above will return 1 row, and the column name will be "TheNewId".

"Ed_P" <an*******@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
Hello Chris,

Thanks for the quick reply. I'll try what you mentioned, do you happen to

have any sample source code to go along with your suggestion?
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: will eichert | last post by:
Greetings. I have a problem with a combo box incorrectly displaying blank items when returning to a form from a modal form. It's fine when the main form first comes up, but gets messed up when the...
1
by: Wayne Aprato | last post by:
I have a client who is running several Access 97 databases that I have written for them. They are about to upgrade to Access 2003. Is the default file format of Access 2003 still Access 2000 the...
3
by: Colin Chudyk | last post by:
Hi, Here is my situation. Can anyone provide insight? I have developed a database in Access 2002. I am planning to distribute it as a split MDE (front) / MDB (back) to be used by the Access...
7
by: Wayne Aprato | last post by:
I have several Access 2003 mde databases. When I try to open them in Access 2002 I get the following error: "The Visual Basic for Applications project in the database is corrupt." ...
2
by: Jeff | last post by:
Does anyone know of any potential problems running a 2000 database with 2003? Also, what about installing all other Office products as 2003 versions but leaving Access as 2002 running a 2000...
10
by: Lauren Wilson | last post by:
Ok I have searched the MS website for info on this. I am totally confused. If I want to deploy an Access 2003 app and allow my users to run it using Access 2003 Runtime, where do I get the...
49
by: Mell via AccessMonster.com | last post by:
I created databases on Access 2003 and I want to deploy them to users. My code was also done using 2003. If they have Ms Access 2000 or higher, will they be able to use these dbs with all code,...
2
by: Hiyella2 | last post by:
Hello, I have a problem with a table in my MS Access 2003 table. The primary key of this table is an autonumber field set to a Long Integer, Yes - no duplicates. The autonumber made it to 10252....
1
by: bytes access nubie | last post by:
Hello. I'm trying to create one macro in Access 2003 that will delete a field (called ID) in a table. I then need a separate macro that will *add* a field back in called ID w/type of autonumber. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.