473,386 Members | 1,743 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,386 software developers and data experts.

How do i keep the leading zeros in text

2
hi, i have a field that concatenates a prefix and an auto number, e.g, Field1= 001, Field2=project. in field 3, my formula reads, left(field1;3) & field2. the result is PR1, i need it to be PR001. the leading zeros in filed1 seems to drop in field3. how do i prevent this?
Nov 14 '16 #1
3 3814
PhilOfWalton
1,430 Expert 1GB
Try

Expand|Select|Wrap|Line Numbers
  1. Field2 & Right(Format(1,"0000000"),3)
  2.  
Format (Field1, "0000000") ensures that there are lots of leading zeros, and then we cut it to the right hand 3 digits.

Simpler would be

Expand|Select|Wrap|Line Numbers
  1. Field2 & Format(1,"000")
  2.  
The possible snag with this is it is fixed at 3 digits. The first method allows you to pass a parameter od how many digits to display.

Phil
Nov 14 '16 #2
nerosh
2
Hi Phil, thank you for your speedy response. my formula now reads: Left([Field1];3) & "-" & [Field2] & Right(Format(1,"0000000"),3), however i get an error that the expression contains invalid syntax. I've tried both methods and get the same error. apologies if this is a dumb question - learning as i go along
Nov 15 '16 #3
PhilOfWalton
1,430 Expert 1GB
Sorry, my fault.

Your question is a bit confusing.
If Field2 = "PR" and Field1 = 1 then the correct (I hope) expression should be

Expand|Select|Wrap|Line Numbers
  1. Field2 & Right(Format(Field1,"0000000"),3)
  2.  
The invalid syntax you mentioned, apart from anything else, is that you have a semicolon in Left([Field1];3) instead of a comma.

You can of course add the dash if you want it

Expand|Select|Wrap|Line Numbers
  1. Field2 & "-" & Right(Format(Field1,"0000000"),3)
  2.  
Phil
Nov 15 '16 #4

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

Similar topics

5
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in...
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...
6
by: Clint Stowers | last post by:
Using A2k Exporting a query to a CSV file. The problem is any text fields (i.e. 000345) lose any leading zeros. Exporting to an excel file this problem does not exist. Tried to create a...
5
by: OneDay | last post by:
I've got a field that has some old data with text in it, but all forward data will be a 3 digit number. But many of the numbers are still only 2 digits. I would like to force the leading zero in...
6
by: Brian Campbell | last post by:
HELP! SOS! I have a field that I'm trying to format within a query. The results from my field "Appointment.EMP_FILE_NB" give various numbers: (e.g.: 213 105523 125400 1245 834
2
by: chris | last post by:
Hi, I have a simple ms access application that allows you to scan barcodes in to a form which stores them in the database. The barcodes are 6 digits in length e.g. 555666 but my handheld...
3
by: ineedahelp | last post by:
Can anyone help me...I am trying to output my access report to excel. One of my fields is formatted as text, but excel is dropping leading zeros...only on the records where all values are numeric. ...
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...
0
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL =...
15
by: Deekay | last post by:
Is there a way to preserve possible leading zeros in a number even when it is passed as text? I have this code on a form which runs off a command button taking two values from user input, passing...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.