PC Review


Reply
Thread Tools Rate Thread

Convert integer to formatted text string..

 
 
Jeremy Sculler
Guest
Posts: n/a
 
      5th Sep 2006
If I have a column with integers:

12345
2345
345

... and want to leftpad the first digits with zeros and insert a space in
front of the two last digits like this:

12345 -> 0123 45
2345 -> 0023 45
345 -> 0003 45

how can that be done in access..?

regards

Jeremy
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      5th Sep 2006
Function PadNumber(NumberIn As Long) As String
Dim strNumber As String

strNumber = Format(NumberIn, "000000")
PadNumber = Left(strNumber, 4) & " " & _
Mid(strNumber, 5)

End Function

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jeremy Sculler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If I have a column with integers:
>
> 12345
> 2345
> 345
>
> .. and want to leftpad the first digits with zeros and insert a space in
> front of the two last digits like this:
>
> 12345 -> 0123 45
> 2345 -> 0023 45
> 345 -> 0003 45
>
> how can that be done in access..?
>
> regards
>
> Jeremy



 
Reply With Quote
 
Rick Brandt
Guest
Posts: n/a
 
      5th Sep 2006
Jeremy Sculler wrote:
> If I have a column with integers:
>
> 12345
> 2345
> 345
>
> .. and want to leftpad the first digits with zeros and insert a space
> in front of the two last digits like this:
>
> 12345 -> 0123 45
> 2345 -> 0023 45
> 345 -> 0003 45
>
> how can that be done in access..?


=Format(Format([FieldName], "000000"), "0000 00")

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      5th Sep 2006
"Rick Brandt" <(E-Mail Removed)> wrote in message
news:ZkjLg.6091$(E-Mail Removed)...
> Jeremy Sculler wrote:
>> If I have a column with integers:
>>
>> 12345
>> 2345
>> 345
>>
>> .. and want to leftpad the first digits with zeros and insert a space
>> in front of the two last digits like this:
>>
>> 12345 -> 0123 45
>> 2345 -> 0023 45
>> 345 -> 0003 45
>>
>> how can that be done in access..?

>
> =Format(Format([FieldName], "000000"), "0000 00")


I knew there had to be a better way...!

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



 
Reply With Quote
 
Rick Brandt
Guest
Posts: n/a
 
      5th Sep 2006
Douglas J. Steele wrote:
> "Rick Brandt" <(E-Mail Removed)> wrote in message
> news:ZkjLg.6091$(E-Mail Removed)...
>>
>> =Format(Format([FieldName], "000000"), "0000 00")

>
> I knew there had to be a better way...!


Actually, I was fully expecting someone to come up with a better way than
mine :-)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


 
Reply With Quote
 
Jamie Collins
Guest
Posts: n/a
 
      6th Sep 2006

Rick Brandt wrote:
> >> =Format(Format([FieldName], "000000"), "0000 00")

> >
> > I knew there had to be a better way...!

>
> Actually, I was fully expecting someone to come up with a better way than
> mine :-)


How about

Format([FieldName], "0000 00")

Jamie.

--

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      6th Sep 2006
"Jamie Collins" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Rick Brandt wrote:
>> >> =Format(Format([FieldName], "000000"), "0000 00")
>> >
>> > I knew there had to be a better way...!

>>
>> Actually, I was fully expecting someone to come up with a better way than
>> mine :-)

>
> How about
>
> Format([FieldName], "0000 00")


D'oh! <g>

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



 
Reply With Quote
 
Rick Brandt
Guest
Posts: n/a
 
      6th Sep 2006
Douglas J. Steele wrote:
> "Jamie Collins" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > Rick Brandt wrote:
> > > > > =Format(Format([FieldName], "000000"), "0000 00")
> > > >
> > > > I knew there had to be a better way...!
> > >
> > > Actually, I was fully expecting someone to come up with a better
> > > way than mine :-)

> >
> > How about
> >
> > Format([FieldName], "0000 00")

>
> D'oh! <g>


That is what I tested first and I could have sworn that there was somethign
about it that didn't work correctly on the shorter numbers. However, in trying
it now I can't see any problems. (?)


--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com



 
Reply With Quote
 
 
 
Reply

« Links | curso web »
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
How to convert from string to integer? Allen Maki Microsoft Dot NET Framework Forms 1 1st May 2007 09:57 AM
convert HEX string into integer :) Microsoft C# .NET 3 26th May 2006 08:37 PM
How to convert hex string to integer Tanja Krammer Microsoft C# .NET 3 8th Apr 2006 08:46 PM
convert string to integer (hex) Panhuber Astrid Microsoft Dot NET Compact Framework 3 2nd Mar 2004 06:34 AM
convert string to integer? djc Microsoft Access Queries 4 8th Jan 2004 07:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 PM.