Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Format Zip Code for Barcoding

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 06 Jul 2007 15:32 GMT
I have just inherited a system which consists of WORD 2000 forms and macros.  
Many of the forms are launched by another application which passes parameters
to the form; so I have little control over the format of the input data.  Zip
codes are passed to the forms as either five digits or nine digits with no
dash.  I have a routine that will create a barcode for any zip code formatted
as "12345" or "12345-6789", but will not work for "123456789".   How can I
change "123456789" into "12345-6789"?
Graham Mayor - 06 Jul 2007 15:45 GMT
If you can do this with fields in your document - see the Zip section of
http://www.gmayor.com/formatting_word_fields.htm

You can replace 9 digits with the required format in a document using
replace
i.e. a wildcard replace of
([!0-9][0-9]{5})([0-9]{4}[!0-9])
with
\1-\2
Much depends on where and how you want to replace the numbers.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> I have just inherited a system which consists of WORD 2000 forms and
> macros. Many of the forms are launched by another application which
[quoted text clipped - 4 lines]
> "12345-6789", but will not work for "123456789".   How can I change
> "123456789" into "12345-6789"?
Paul - 06 Jul 2007 17:20 GMT
Thank you very much, Graham, but the VB editor is not liking the "find" part
of the replace statement as I am using it.  It flags the [0-9] after the
first [!0-9], and says "Compile error:  expected: )".  Here is the code as I
have it:

If Len(ZIP$) = 9 Then

   Replace(ZIP$,([!0-9][0-9]{5})([0-9]{4}[!0-9]),\1-\2)
     
End If

I'm sure it's just a syntax error, but I'm not seeing it.

> If you can do this with fields in your document - see the Zip section of
> http://www.gmayor.com/formatting_word_fields.htm
[quoted text clipped - 15 lines]
> > "12345-6789", but will not work for "123456789".   How can I change
> > "123456789" into "12345-6789"?
Russ - 07 Jul 2007 04:25 GMT
Paul,
Graham was not talking about using the Replace() function, he meant the
.Find method in Word VB*A*, which uses those wildcards. This forum is for
word.vba.general not VB.
However they are close enough that I would suggest using the format()
function.
ZIP$ = Format(ZIP$,"#####-####")

> Thank you very much, Graham, but the VB editor is not liking the "find" part
> of the replace statement as I am using it.  It flags the [0-9] after the
[quoted text clipped - 28 lines]
>>> "12345-6789", but will not work for "123456789".   How can I change
>>> "123456789" into "12345-6789"?

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Paul - 09 Jul 2007 15:56 GMT
Russ,

Thank you.  The format function did the trick.  Part of the problem was my
unfamiliarity with the barcode logic.  I thought I needed some more complex
VBA code, when a simple VB statement was all I really needed.

Paul

> Paul,
> Graham was not talking about using the Replace() function, he meant the
[quoted text clipped - 36 lines]
> >>> "12345-6789", but will not work for "123456789".   How can I change
> >>> "123456789" into "12345-6789"?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.