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!

AutoNumber Primary Key and Input Mask

Status
Not open for further replies.

Milin

Technical User
Jan 5, 2000
33
US
Hello, <br>
<br>
Is it possible to create a primary key on an autoNumber field, AND set up something like an Input Mask (like a word as a prefix)to the autonumber? I collect data monthly from an outside source that &quot;starts over&quot; every month, but I need to track each individual record in the history that I'm keeping.<br>
<br>
Thanks, <br>
Milin
 
No. An autonumber is an integer generated by Access. So you cannot add a word before it. Use autonumber to create the internal number and have a separate field that has the external number and use a mask for that if you need to. A date field could contain the month too...
 
If you want to generate an number automatically I use this procedure.<br>
then you can add what ever you want in front or behind or in the middle.<br>
<br>
open table and get the last RA number used<br>
Dim MyDB As Database, MySet As Recordset<br>
Set MyDB = DBEngine.Workspaces(0).Databases(0)<br>
Set MySet = MyDB.OpenRecordset(&quot;Last-RA-Number&quot;)<br>
MySet.MoveFirst<br>
MySet.Edit<br>
Temp1 = MySet.Fields(&quot;Last_RA_Number&quot;)<br>
ME![MyField] = Date(now) & Temp1<br>
Temp2 = Temp1 + 1<br>
MySet.Fields(&quot;Last_RA_Number&quot;) = Temp2<br>
MySet.Update<br>
MySet.Close<br>
MyDB.Close<br>
<br>
Now on the above line ME![MyField] = <br>
do what ever you want here<br>
<br>
I don't think I have the syntax right but you get the idea.<br>
Also you need a table which has one field that stores the number you want to increment in my case it's &quot;Last RA number&quot;. A table is called Last_RA_Number with one field called &quot;Last_RA_Number&quot;.<br>
Now the field I am using is a Double NOT an autonumber in the &quot;Last_RA_Number&quot; table<br>
<br>
OK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top