The following Access function can be used to generate Postnet codes.
Postnet (Postal Numeric Encoding Technique) is used by the Postal Service
to automate the routing of your mail.  This technique improves the speed
and reliability of mail delivery.

The function takes a ZIP or ZIP+9, adds a code for the framing bar at
the beginning and end, adds a checksum code, and removes any extraneous
characters (such as the '-' the may be in a ZIP+9, e.g., 80321-4093).

The resulting string can be printed using the ZIPBAR TrueType font (found
in Lib 15) or can be adapted for other Postnet fonts.

To use the PostNet function, create a text control on a report, set the
font to the Postnet font (e.g., from ZIPBAR) and set the control's source
to "=PostNet([ZIP])" where ZIP is your ZipCode field.

The PostNet would typically be printed as the first line of your mailing
label, immediately above the name of the recipient.

Thanks to Jay Munro for his article on Postnet in the Dec 8, 1992 issue
of PC Magazine (pg. 405).

This is one of my first Access Basic funtions and comments or suggestions
are welcomed.

Kevin Dybdal
75766,20


Function PostNet (ZipCode)
    Dim OutStr As String, TmpStr As String, ChrStr As String
    Dim ChkSum As Integer

    ' Default to no PostNet code
    PostNet = ""

    ' Exit early if there is nothing to convert
    If IsNull(ZipCode) Or IsEmpty(ZipCode) Then
        Exit Function
    End If

    ' Set up local variables
    TmpStr = ZipCode
    ChkSum = 0
    OutStr = "s"        ' Start code

    ' Loop through, throwing away non-numeric characters
    While (Len(TmpStr) > 0)
        ' Grab the first character
        ChrStr = Left$(TmpStr, 1)
        ' Check to see if it's a number
        If IsNumeric(ChrStr) Then
            OutStr = OutStr & ChrStr        ' Append to output
            ChkSum = ChkSum + Val(ChrStr)   ' Add to checksum
        End If
        TmpStr = Mid$(TmpStr, 2)            ' Skip over first character
    Wend

    ' Compute Checksum digit
    ChkSum = (10 - (ChkSum Mod 10)) Mod 10
    ChrStr = Trim(Str(ChkSum))

    ' Append Checksum digit and stop code
    OutStr = OutStr & ChrStr
    OutStr = OutStr & "s"

    ' Verify that the output string is the right length
    ' ZIP   =  8 (5 digit zip + start, stop and checksum codes)
    ' ZIP+4 = 12 (9 digit zip + start, stop and checksum codes)
    If Len(OutStr) = 8 Or Len(OutStr) = 12 Then
        PostNet = OutStr
    End If
End Function
