Go Back   Rhinocerus > Newsgroup > Newsgroup comp.databases.ms-access

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-15-2006, 03:00 AM
MLH
Guest
 
Posts: n/a
Default Trying to format zip code

Have zip codes in text table field.
Some are 12345 and some are 123456789.

Using Format([ZipCode],"00000-0000") doesn't
produce desired results. Am trying to display
12345-6789 or 12345
depending on whether there's 9-chars or 5-chars
in the [ZipCode] field.
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 06-15-2006, 03:05 AM
fredg
Guest
 
Posts: n/a
Default Re: Trying to format zip code

On Wed, 14 Jun 2006 23:00:09 -0400, MLH wrote:

> Have zip codes in text table field.
> Some are 12345 and some are 123456789.
>
> Using Format([ZipCode],"00000-0000") doesn't
> produce desired results. Am trying to display
> 12345-6789 or 12345
> depending on whether there's 9-chars or 5-chars
> in the [ZipCode] field.


Use an unbound text control.
Set it's control source to:
=IIf(Len([Zip])>=6, Left([Zip],5) & "-" & Right([Zip],4),[Zip[)
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Reply With Quote
  #3 (permalink)  
Old 06-15-2006, 03:08 AM
pietlinden@hotmail.com
Guest
 
Posts: n/a
Default Re: Trying to format zip code


MLH wrote:
> Have zip codes in text table field.
> Some are 12345 and some are 123456789.
>
> Using Format([ZipCode],"00000-0000") doesn't
> produce desired results. Am trying to display
> 12345-6789 or 12345
> depending on whether there's 9-chars or 5-chars
> in the [ZipCode] field.


base your report on a query or use an unbound control.
iif(Len$(ZipCode)=5,ZipCode,left$(ZipCode,5)&"-"&right$(Zipcode,4))

Reply With Quote
  #4 (permalink)  
Old 06-15-2006, 03:11 AM
MLH
Guest
 
Posts: n/a
Default Re: Trying to format zip code

Well, that's another way.

I could use this...
IIf(Len([ZipCode])>5,Format$([ZipCode],"00000-0000"),Format$([ZipCode],"00000"))

But I was hoping to accomplish it all within the confines
of the Format function. Perhaps its not possible.
Reply With Quote
  #5 (permalink)  
Old 06-15-2006, 03:23 AM
Larry Linson
Guest
 
Posts: n/a
Default Re: Trying to format zip code

"MLH" wrote

> Have zip codes in text table field.
> Some are 12345 and some are 123456789.
>
> Using Format([ZipCode],"00000-0000") doesn't
> produce desired results. Am trying to display
> 12345-6789 or 12345
> depending on whether there's 9-chars or 5-chars
> in the [ZipCode] field.


The following function (without error handling or content checking other
than length, for simplicity) seems to work OK for me on a few ZIP codes that
I passed it, in string form.

Function FmtZIP(pstrZIP As String) As String

If Len(pstrZIP) = 5 Then
FmtZIP = Format(pstrZIP, "@@@@@")
ElseIf Len(pstrZIP) = 9 Then
FmtZIP = Format(pstrZIP, "@@@@@\-@@@@")
Else
FmtZIP = "*** ERROR: " & pstrZIP & " is not a valid ZIP"
End If

End Function

Larry Linson
Microsoft Access MVP


Reply With Quote
 
Reply

Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FORMAT quandary David Nasser Newsgroup comp.soft-sys.sas 0 12-06-2005 04:37 PM
Re: A case when the location of a format statement in a data step Michael S. Zdeb Newsgroup comp.soft-sys.sas 0 07-07-2005 01:28 PM



All times are GMT. The time now is 09:14 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.