473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Leading zero's variable number length and variable number of leading 0's

I have 2 fields where I track pass numbers which need to be calculated fields. These numbers are 6 to 8 digits long and have varying number of leading 0's (very novice level) at access how can I format these fields to accept these 0s and show them
Jul 25 '16 #1
9 3514
PhilOfWalton
1,430 Expert 1GB
as en example
Expand|Select|Wrap|Line Numbers
  1. format(23.83,"00000000.00")
  2. gives 00000023.83
  3.  
Is that what you want?

Phil
Jul 25 '16 #2
The difficulty I am having is that no matter what I do I can only make it have an exact number of digits when I need it to be able to vary because the numbers have to be exact if I make it eight digits long then it adds additional zeros to the six digit numbers and so on how can I get it to allow variable lengths of numbers and variable numbers of leading zeros example pass numbers could be 001214 or 000503 or 0925645 depending on the pass type and the way this works is these numbers are subtracted by last number of sequence minus first number of sequence +1 to get the quantity of passes sold so they have to be number fields.
Jul 25 '16 #3
PhilOfWalton
1,430 Expert 1GB
Are you saying that the number 0925645 should be regarded as 2 separate numbers 0925 and 645, (I don't know where the split should be).
If so why aren't they in 2 separate fields.

AFAIK to get leading zeros, you have to format a number, and a formatted number is text. You can then get the left four letter ("0925") and convert it back to a number using the CLng function, and same thing with the rest of the text ("645")

Really need to see your tables and the calculations in more detail to advise with any certainty.

Phil
Jul 26 '16 #4
There are two identical fields I have the issue with one is first pass used and can any combination of up to 7 numbers. The second is last pass number which is the same way. Both fields could have as many as six leading zeros or as few as no leading zeros the numbers are either 6 or seven digits long depending on the type of pass or whether we grow into more digits as the numbers become used. The two fields will be calculated as (last pass number - first pass number +1) in order to find the quantity sold from the number sequence. Example first pass # 0999998 and last pass number 1000010 or first pass # 000998 last pass # 001010 the fields have to be able to handle any number including 0000001 or 0000001 or 999999 or 0999999. Exactly as they are entered without changing the system changing the data and removing the 0s or adding 0s.
Jul 26 '16 #5
zmbd
5,501 Expert Mod 4TB
VORTEGA:
In Access, numbers are numbers, doesn't matter how many leading or trailing zeros part of the number for any field that is typecast as a numeric datatype.

To make sure I am perfectly clear:
000000 == 00000 == 0000 == 000 == 00 == 0
000001 == 00001 == 0001 == 001 == 01 == 1
000002 == 00002 == 0002 == 002 == 02 == 2
(...)
099999 == 99999

Furthermore
099999 - 000001 = 099998
099999 - 00001 = 099998
099999 - 0001 = 099998
099999 - 001 = 099998
099999 - 01 = 099998
099999 - 1 = 099998

Trailing zeros before the decimal and between a decimal and any numerical value are of course a different matter as they serve as placeholders.

So if you want to have the leading zeros matter then we need to look at a text field. Perhaps if you will tell us why this formatting is so important we may be able to provide you with a better solution.

If the zeros are only for cosmetic reasons then
Open the table in design view
select the field
In the general tab of the field property enter 000000
Your numbers will always display at least six zeros (the user enters the value of zero for the field) or the correct number of zeros to pad for a six character numeric value.

Attached Images
File Type: jpg 966911_numeric_formating.jpg (47.8 KB, 1547 views)
Jul 26 '16 #6
jforbes
1,107 Expert 1GB
Typically, if you want to manage a number and preserve the leading Zeros, you would use a String instead of a Number, because leading Zeros aren't significant digits, so they are ignored by Access... and pretty much any other computer program. Zmbd does a good job at explaining why the leading zeros are not significant as they have no impact on the result of any Math performed on the Number. He also shows how to format number for leading zeros, which may be what your after.

But if you are saying you need to manage two different length numbers with varying lengths then I'm guessing you aren't really using Numbers, but String values that are comprised of Numbers. I would change your DataTypes to String and then use Val() method when you perform your Math.
Jul 26 '16 #7
It is for inventory tracking of parking passes so unfortunately all the numbers matter, each has a unique number which may or may not have leading zeros and may be 6 or 7 digits in length currently and possibly get longer as time goes on,normally wouldn't be an issue because they normally have a two or three digit alpha prefix, but since we want to calculate the number sold based on (last pass # minus first pass # + 1= total passes sold) we have to be able to calculate the field for math purposes as well which I don't believe we would be able to do if the prefix letters were included in the fields. So currently the prefixes SC, GDP, and AHS are a drop down in a separate field. If there is a way to just allow the prefix in the field and still calculate the numbers then that would actually be the Ideal solution. Is that possible?
Jul 26 '16 #8
zmbd
5,501 Expert Mod 4TB
Easiest method would be to have two fields, one with the alpha-part and the second with the numeric part.

However, I've been playing with the RegEx available in newer versions of Access now and came up with:
Expand|Select|Wrap|Line Numbers
  1. Function ReturnNumeric(zInStr As String) As Long
  2.     Dim zRegExObj As Object
  3.     Set zRegExObj = CreateObject("vbscript.regexp")
  4.     With zRegExObj
  5.         .Pattern = "\d+"
  6.         If .test(zInStr) Then ReturnNumeric = .Execute(zInStr)(0)
  7. 'Why Execute()(0)? In vba test (0) not required
  8. 'in SQL test (0) require or too few augments error
  9.     End With
  10.     Set zRegExObj = Nothing
  11. End Function
You can then use this function against data such as
Expand|Select|Wrap|Line Numbers
  1. [TicketSN_Start][TicketSN_END][Tickets_Sold]
  2.      AG00001       AG006             5 
  3.     BGX01568       BGX1769          201
Expand|Select|Wrap|Line Numbers
  1. SELECT TicketSNFeedTable.pk
  2.    , TicketSNFeedTable.TicketSN_Start
  3.    , TicketSNFeedTable.TicketSN_End
  4.    , (ReturnNumeric([ticketSN_END])
  5.       -ReturnNumeric([ticketSN_Start])) 
  6.       AS Tickets_Sold
  7. FROM TicketSNFeedTable;
This is a very simple SQL in that there is no check for the prefix characters (so if you take the first row of the example data above: AG006 - XYZ0001 = 5 ) nor if the ending serial number is less than the starting serial number (XYZ0001 - AG006 = -5 ) I am sure such could be implemented within SQL; however, might be easier in VBA.

Quick reference and tutorial on:
VBScript - Regular Expressions keep in mind that this is a vbscript site NOT a vba site so the other coding here will not always directly port in to VBA.
Jul 26 '16 #9
jforbes
1,107 Expert 1GB
That's a slick solution ZMBD. Another very helpful resource for RegEx that I've come to rely on: RegExr is an online tool to learn, build, & test Regular Expressions It's a reference site, but it also has a very well written interface to test RegExs.
Jul 27 '16 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Girish | last post by:
Hey, This is what I would like to do: =========== Declare @chvBOLNumber Set @chvBOLNumber='0001234' Select * from BOL where BOLNumber=@chvBOLNumber I want to return the row/rows when...
1
by: mmmgood1 | last post by:
Help, I'm linking an excel spreadsheet in access and I have datafields with leading zeros (01021). When the file is linked in access, I get a #num in the field with the leading zeros. The zeros...
5
by: jack | last post by:
Hello, I have a number that is 6 places long. I would like: "16" to be "000016" "116" to be "000116" and so on.
2
by: Sameh Ahmed | last post by:
Hello there I have a couple of questions which I hope somebody will help me with. First, in VBscript, I used to use the function "string", which will take an integer and a character, then creates...
7
by: vivekian | last post by:
Trying to write a function which can accept variable number of arguments of the same data type , ranging from 1 ... n . What would be the best way to go about this. Thanks, vivekian
10
by: Praveen.Kumar.SP | last post by:
Hi Could anyone solve the problem for the code below The Code: #include "stdio.h" #include "iostream.h" void Temp( int a, char* str,...)
4
by: ashish.sadanandan | last post by:
Hi, I'm new to XML and just started reading some documentation on W3C compliant schemas recently. The XML file I'm generating is for an embedded application and so size is of extreme importance....
6
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for...
2
by: cmdolcet69 | last post by:
Does anyone know how to set a property to display the leading zeros in the numberic updown control for vb 2005? I'm using the control and want to input a value of 01 however it will just show 1?
1
by: lazerbrain | last post by:
How can I represent eg. 23633.78 with leading zeros in format: 000000002363378 In other words the field is 15 characters length and when I put number I want to place leading zeroes on the left....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.