A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Changing Text Field to Autonumber Field



 
 
Thread Tools Display Modes
  #1  
Old August 29th, 2008, 07:04 PM posted to microsoft.public.access.tablesdbdesign
JWeaver
external usenet poster
 
Posts: 90
Default Changing Text Field to Autonumber Field

I have been asked to help get something changed on a database (someone else
created it). The database has 4 tables, all of which have a Primary Key
field named WorkerID set as a Text field for 3 characters. The user must
enter a number into the field when entering new employees which is a problem
since they do not know what the last number used and will get an error if
they enter one that has already been used.

How can I fix this so that the tables will automatically assign a number to
new entries in the tables? The tables are set up so that relationships exist
between all of them on this WorkerID field.

I have gotten help here in the past with other problems and know that you
folks provide excellent guidance. Looking forward to seeing what you suggest
for me to do!

Thanks!!!
--
JWeaver
  #2  
Old August 29th, 2008, 09:21 PM posted to microsoft.public.access.tablesdbdesign
Klatuu
external usenet poster
 
Posts: 7,074
Default Changing Text Field to Autonumber Field

You say it is a 3 character text field and you enter numbers, So I am
assuming it has values like 001, 002, 003, etc.
If this is correct, then you can find the next available number using the
DMax function when you want to add a new record:

Function NextWorkerID() As String
Dim strNextNum As String

strNextNum = Nz(DMax("WorkerID", "SomeTable"), "000")
NextWorkderID = Fomat(Clng(strNextNum) + 1, "000")
End Function

--
Dave Hargis, Microsoft Access MVP


"JWeaver" wrote:

I have been asked to help get something changed on a database (someone else
created it). The database has 4 tables, all of which have a Primary Key
field named WorkerID set as a Text field for 3 characters. The user must
enter a number into the field when entering new employees which is a problem
since they do not know what the last number used and will get an error if
they enter one that has already been used.

How can I fix this so that the tables will automatically assign a number to
new entries in the tables? The tables are set up so that relationships exist
between all of them on this WorkerID field.

I have gotten help here in the past with other problems and know that you
folks provide excellent guidance. Looking forward to seeing what you suggest
for me to do!

Thanks!!!
--
JWeaver

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:09 AM.


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