473,506 Members | 16,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining 2 fields into another 3rd field and leading zeros

11 New Member
Hi, I'm trying to combine the text in two original fields and paste them into another 3rd field on a form, but the problem is that there are leading zeros in both original fields, which access does not copy into the 3rd field.

For example, if field 1 = 07 and field 2 = 0001, i'd like the 3rd field to be 070001, but instead access returns 71 in the 3rd field.

Adding to the complexity a bit is that field 2 is an autonumber field. so when i want that autonumber field to have a value when creating a new record, i have to fill in at least one of the other fields on the form. I'll be using field 4 for this.

The code I'm currently using is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Field4_Exit(Cancel As Integer)
  2. Me.Field3= Me.Field1 & Me.Autonumber
  3. End Sub
How can i modify this code so that the leading zeros are included?

Thanks a lot!
Mar 14 '07 #1
3 2269
Rabbit
12,516 Recognized Expert Moderator MVP
Hi, I'm trying to combine the text in two original fields and paste them into another 3rd field on a form, but the problem is that there are leading zeros in both original fields, which access does not copy into the 3rd field.

For example, if field 1 = 07 and field 2 = 0001, i'd like the 3rd field to be 070001, but instead access returns 71 in the 3rd field.

Adding to the complexity a bit is that field 2 is an autonumber field. so when i want that autonumber field to have a value when creating a new record, i have to fill in at least one of the other fields on the form. I'll be using field 4 for this.

The code I'm currently using is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Field4_Exit(Cancel As Integer)
  2. Me.Field3= Me.Field1 & Me.Autonumber
  3. End Sub
How can i modify this code so that the leading zeros are included?

Thanks a lot!
Expand|Select|Wrap|Line Numbers
  1. Private Sub Field4_Exit(Cancel As Integer)
  2. Me.Field3 = Right("0" & Me.Field1, 2) & Right("000" & Me.Field2, 4)
  3. End Sub
Mar 14 '07 #2
travellinman
11 New Member
Thanks! this works great
Mar 15 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
No problem, good luck.
Mar 15 '07 #4

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

Similar topics

2
4696
by: Kristian | last post by:
Hey, I have some problems combining 2 fields in a query. For example: the first field is "1050-04" and the second field is "02". However, when i try to combine these two the zero in the...
1
1500
by: Bert | last post by:
In a select query I am attempting to combine two fields: One where Field1 = "AL" the other Field2 = "01" I am writing: NewString = & Even though Field2 is a string, the leading zero...
5
2096
by: M.Stanley | last post by:
Hi, I'm attempting to create a query that will combine 2 columns of numbers into one. The followng comes from 1 table with 4 fields (A,B,C,D) A B RESULT 700 000 700000 700 001 ...
4
3118
by: Omey Samaroo | last post by:
Dear Access Gurus, Can anyone provide me with some much needed assistance. I would like to combine the contents of 3 text fields into one field. Can someone provide some code or a method to do...
5
20391
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...
4
4010
by: Sally Sally | last post by:
Hi all, I am wandering about the pros and cons of creating a separate serial field for a primary key when I already have a single unique field. This existing unique field will have to be a...
2
1868
by: Jimmy | last post by:
Here's my issue. I'm using a calculated control to combine two fields on a form & report. The two fields are RecordID (the autonumber primary key) and a field named ProductCost. The idea is to...
6
7734
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...
5
3424
by: Rowan | last post by:
Hi, I am somewhat new to .net and c#. (What I learned in previous co has to be unlearned). I am doing something that seems simple but I think there is a better way than how I learned to do it. ...
0
7307
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,...
0
7370
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...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.