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  

Automatic Preceeding Zeros in a field e.g. 00001234



 
 
Thread Tools Display Modes
  #1  
Old June 18th, 2004, 08:11 PM
DD
external usenet poster
 
Posts: n/a
Default Automatic Preceeding Zeros in a field e.g. 00001234

I have a serial number field that will consist of 8
numbers. Right now, the young serials only consist of 3
numbers but we would like to have the young numbers which
are not yet 8 characters be preceeded by zeros without the
user having to input the zeros. For example serial
00001234 - I would like the user only to be required to
enter 1234 and have the database convert this to 00001234.
Thanks in advance!
  #2  
Old June 18th, 2004, 10:50 PM
Steve Schapel
external usenet poster
 
Posts: n/a
Default Automatic Preceeding Zeros in a field e.g. 00001234

DD,

Actually, it is not necessary to "convert" the number. If it is in fact
a number, it will be stored as a number, and you can't put leading
zeros. But this is the actual data in the tables as such, and since you
don't normally look at the tables anyway, it doesn't really matter.
Instead, you can leave the data as a number, but just use the Format
property of the applicable textboxes on your forms and reports to
display with leading zeros. Set the Format property to...
00000000

--
Steve Schapel, Microsoft Access MVP


DD wrote:
I have a serial number field that will consist of 8
numbers. Right now, the young serials only consist of 3
numbers but we would like to have the young numbers which
are not yet 8 characters be preceeded by zeros without the
user having to input the zeros. For example serial
00001234 - I would like the user only to be required to
enter 1234 and have the database convert this to 00001234.
Thanks in advance!

  #3  
Old June 19th, 2004, 05:55 AM
Jay Vinton
external usenet poster
 
Posts: n/a
Default Automatic Preceeding Zeros in a field e.g. 00001234

are not yet 8 characters be preceeded by zeros without the
user having to input the zeros.


If the data needs to be a number, you must deal with the formatting in code at runtime. If your objective is to always have 8 characters in the table, then it should be type String.

Assuming the second case, make the serial number type Text and massage it in code before saving.

This is a good time to stop and think. Will today's serial number format be workable in the future? What if you want to change "00000123" to "ABC-0123" or "ABC-XY-1234567890-P"? If you plan ahead, you'll save a lot of grief when things change.

To solve your immediate problem:

Dim str as String

str = CStr(123)

Do While (Len(str) 8)

str = "0" & str

Loop

' str = "00000123"

Jay
 




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 07:00 PM.


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