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

Trying to format zip code

MLH
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.
Jun 15 '06 #1
4 14288
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
Jun 15 '06 #2

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))

Jun 15 '06 #3
MLH
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.
Jun 15 '06 #4
"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
Jun 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Helmut Jarausch | last post by:
Hi, is there a format code to return an unsigned int to Python via Py_BuildValue? Just using code 'i' gives negative values for values greater than 2**31. I've tried the code 'I' (with python...
0
by: Josiah Carlson | last post by:
Good day everyone, I have produced a patch against the latest CVS to add support for two new formatting characters in the struct module. It is currently an RFE, which I include a link to at the...
0
by: Brian Hampson | last post by:
I'd like to be able to write an add-in that would rotate my display picture, through my set of display pics for MSN Messenger. I suppose I'm looking for an add-in API, and some pointers to how to...
1
by: Tim::.. | last post by:
Hi can someone please tell me why I keep getting the following error when I execute this code! I have checked the database and it seems like everything is set as integer for pageID! Error:...
5
by: kirk_korver | last post by:
Group, I'm trying to understand the problem with the following code. The problem I get is associated with the line "int fmt = format(); " at the bottom of the line. The error I get says that ...
1
by: dipalrana | last post by:
What is the format code for Nokia N72? Samsung SGH E250V?
3
Chittaranjan
by: Chittaranjan | last post by:
Hi All, I am not sure how to change the date format in PostgreSQL. I have the dates stored in the database as yyyy-mm-dd HH:MM:SS+TimeZone to get the GMT time (Ex: 2008-02-28 14:03:23+05:30). But...
3
Tenneyson
by: Tenneyson | last post by:
Hi Can anybody help! how do i format this code so that the results printed will be aligned. E.G. should print like this First Funeral Assurance Co. PolicyNo : F000001 Name : ...
5
by: jerrydigital | last post by:
Hi, I have a registration form that uses the javascript validation code I have posted below. I am trying to verify that the user enters a birthdate in the format 01/11/1999 Anyone know how I...
1
by: fraggle10 | last post by:
Hi there I am trying to build a chat client in PHP and would appreciate any help please thanks again
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.