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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert sequential numbers with leading zeros into a table using query

Status
Not open for further replies.

aisgeek

MIS
Jan 13, 2003
3
US
I am using Access ’97 and am trying to insert sequential numbers with leading zeros into a table using a make table query and am stumped. Is this even possible using a query?
 
Hi!

Use a public function:

Public Function basSeqNums() As String

basSeqNums = Format(Forms!frmParameters!txtSeqNum, "0000")
Forms!frmParameters!txtSeqNum = Forms!frmParameters!txtSeqNum + 1

End Function

Make a form called frmParameters and add a text box called txtSeqNum setting the initial value to 1. You could use a Static variable in the function or a global variable as well. I usually prefer the form because never trust these variable to initialize correctly. You can call this function from your query as a new field. Also, I set up the format for leading zeros up to four places. If you want more, just add more zeros.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Hi ais,

You got to remember that the field that you store this in must be text. I don't think you can specify 'allow leading zeros' for a numeric field.

Regards,

Darrylle

p.s. Someone will prove me wrong of course! "Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Thanks for the replies. I will attempt using the function first as that does seem logical. This numbering used to identify the number of records to the customer.
Ciao
 
Why not just insert an integer value and format the value with leading zeros when displaying the value? One of the most frequent errors I see in database design is the mis-typing of data columns because developers want to store data in a specific display format. This causes problems with sorting and computations, and usually requires more storage space. Terry L. Broadbent - DBA
SQL Server Page:
If you want to get the best answer for your question read faq183-874.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top