Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / January 2004

Tip: Looking for answers? Try searching our database.

Customizing AutoNumber field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Surya - 20 Jan 2004 18:21 GMT
Can you please help me to customize a field in Access 2000
table?  

I want a customized auto-numbering feature in an Access
2000 Table.  The number should have 7-digits and the first
digit should always be 1.  The next number should
increment by one.  Example: 1000001, 1000002, 1000003 etc.
All these numbers should be unique.  

Can you please send your answer to my email at:
hurjsu@kellyservices.com ?

Thanks,
Surya
Scott McDaniel - 20 Jan 2004 20:18 GMT
You asked in the newsgroup, you get answers in the newsgroup ...

You cannot do this at table level. You must do this via the form that is
used to add records (your ARE using forms for users to add/browse data??).
The easiest way would be to "autoseed" you column with the first value:
1000000. After that, you would use code like this in the BeforeInsert or
AfterInsert event of your form:

Dim lngID As Long

lngID = Nz(DMax("YourIDField")) +1
Me.YourIDField = lngID

To make sure your numbers are unique, add an Index to the underlying table
that includes the field and set Unique = Yes.

If you are asking about customizing the AutoNumbers field ... well, you can
always Format that field to DISPLAY the number any way you like, but the
underlying data will always be stored as a Long datatype. And, there is NO
guarantee that the values will be non-gapped consecutive numbers ... and
using an Autonumber field like that indicates what could be a serious design
flaw in your data.

> Can you please help me to customize a field in Access 2000
> table?
[quoted text clipped - 10 lines]
> Thanks,
> Surya
Ken Ismert - 20 Jan 2004 23:07 GMT
Surya,

Use the following SQL:

ALTER TABLE tblTable ALTER COLUMN AutoID COUNTER (1000000,1);

The first number is the Starting value, the second is the increment.

That said, Doug Steele gives good advice, and you'll likely save
yourself trouble if you heed it.

-Ken

> Can you please help me to customize a field in Access 2000
> table?  
[quoted text clipped - 10 lines]
> Thanks,
> Surya
Surya - 21 Jan 2004 15:32 GMT
My email address is wrongly spelt in my earlier request.  
The correct email address is: DHURJSU@KELLYSERVICES.COM
Thanks,
Surya

>-----Original Message-----
>Can you please help me to customize a field in Access 2000
[quoted text clipped - 12 lines]
>Surya
>.
John Vinson - 21 Jan 2004 17:31 GMT
>My email address is wrongly spelt in my earlier request.  
>The correct email address is: DHURJSU@KELLYSERVICES.COM
>Thanks,
>Surya

Than your request is doubly impolite. This is a public newsgroup,
staffed (if that's the word) by unpaid volunteers like me, who donate
our time to reply to messages. I'm a self-employed consultant; I'll be
happy to provide private EMail support at my usual consulting rate,
which I'll send you upon request. But if it's worth my time to
volunteer to answer your question here, it should be worth your time
to come back to the newsgroup for the reply!

>>-----Original Message-----
>>Can you please help me to customize a field in Access
[quoted text clipped - 8 lines]
>etc.
>>All these numbers should be unique.  

An Autonumber is *not* appropriate in this case; the only function of
an Autonumber is to provide a meaningless, almost-guaranteed (there
are bugs) unique key. They will always have gaps.

Instead, use a Long Integer "custom counter" field, created using VBA
code. You must (no option, table datasheets don't have any usable
events) use a Form to enter your data. The code can be very simple if
it's a one-user system or if there is little or no likelihood of two
people entering a new record at the same time, or it can get pretty
complex in a multiuser system. The simple code would use the Form's
BeforeInsert event:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!txtID = NZ(DMax("[ID]", "[YourTable]"), 1000000) + 1
End Sub

                 John W. Vinson[MVP]    
   Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.