PC Review


Reply
Thread Tools Rate Thread

Concatenate string + Number, losing leading zeros

 
 
bakerstreet@gmail.com
Guest
Posts: n/a
 
      9th Mar 2009
Hello,

I am working on an Access 2007 database. I have a form in this
database with a dropdown for a "topic", which is an alpha value, for
instance "a". I have a text field called "txtCourseNumber" where you
enter a numeric value, and then stores that value into a table. The
field in the table is set as a number, and the format property is set
as 0000

My goal is to concatenate these two fields into a third field called:
"txtNcode" When I attempt the concatenation, I lose any leading zeros
that are in the numeric field "code", even though when I look in the
table the associated cell is filled correctly with the zeros.

I have tried format() and format$() and Cstr() and none seem to give
me the result I am looking for. Here is the code I am using in VBA:


Dim nc As String

nc = cmbTopic.Value & "-" & txtCourseNumber
'I have tried this: format(txtCourseNumber) and format
(txtCourseNumber.value) and format$ for both those.
txtNCode.Value = nc

My end goal is to fill txtNcode with a-0001


Any help would be greatly appreciated!

-KB
 
Reply With Quote
 
 
 
 
Gina Whipp
Guest
Posts: n/a
 
      9th Mar 2009
Try Format([txtCourseNumber],"0000")

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

<(E-Mail Removed)> wrote in message
news:682d2f19-6fdf-4f0a-83b3-(E-Mail Removed)...
> Hello,
>
> I am working on an Access 2007 database. I have a form in this
> database with a dropdown for a "topic", which is an alpha value, for
> instance "a". I have a text field called "txtCourseNumber" where you
> enter a numeric value, and then stores that value into a table. The
> field in the table is set as a number, and the format property is set
> as 0000
>
> My goal is to concatenate these two fields into a third field called:
> "txtNcode" When I attempt the concatenation, I lose any leading zeros
> that are in the numeric field "code", even though when I look in the
> table the associated cell is filled correctly with the zeros.
>
> I have tried format() and format$() and Cstr() and none seem to give
> me the result I am looking for. Here is the code I am using in VBA:
>
>
> Dim nc As String
>
> nc = cmbTopic.Value & "-" & txtCourseNumber
> 'I have tried this: format(txtCourseNumber) and format
> (txtCourseNumber.value) and format$ for both those.
> txtNCode.Value = nc
>
> My end goal is to fill txtNcode with a-0001
>
>
> Any help would be greatly appreciated!
>
> -KB



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      10th Mar 2009
<(E-Mail Removed)> wrote in message
news:682d2f19-6fdf-4f0a-83b3-(E-Mail Removed)...
> Hello,
>
> I am working on an Access 2007 database. I have a form in this
> database with a dropdown for a "topic", which is an alpha value, for
> instance "a". I have a text field called "txtCourseNumber" where you
> enter a numeric value, and then stores that value into a table. The
> field in the table is set as a number, and the format property is set
> as 0000
>
> My goal is to concatenate these two fields into a third field called:
> "txtNcode" When I attempt the concatenation, I lose any leading zeros
> that are in the numeric field "code", even though when I look in the
> table the associated cell is filled correctly with the zeros.
>
> I have tried format() and format$() and Cstr() and none seem to give
> me the result I am looking for. Here is the code I am using in VBA:
>
>
> Dim nc As String
>
> nc = cmbTopic.Value & "-" & txtCourseNumber
> 'I have tried this: format(txtCourseNumber) and format
> (txtCourseNumber.value) and format$ for both those.
> txtNCode.Value = nc
>
> My end goal is to fill txtNcode with a-0001



The Format property of a field or control doesn't affect what is stored,
only how it is displayed. A Number field never stores leading zeros.
You'll need to format the field value with leading zeros as you concatenate
it into your string, like this:

nc = cmbTopic.Value & "-" & Format(txtCourseNumber, "000")


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Concatenate column with leading zeros Bernard Liengme Microsoft Excel Misc 0 25th May 2010 01:28 AM
add text to number field without losing leading zeros Halfpint40601 Microsoft Access 3 28th Jul 2009 07:06 PM
Concatenate with leading zeros Nikki Microsoft Excel Worksheet Functions 2 4th Aug 2008 11:05 PM
Import number data with leading zeros as text without losing leadi =?Utf-8?B?cm52aGlsbA==?= Microsoft Access External Data 5 16th Feb 2007 06:05 PM
I want to concatenate two number fields with leading zeros. =?Utf-8?B?dHVybmVyYg==?= Microsoft Access Security 1 21st Apr 2006 10:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:25 AM.