actually, even your coding doesn't work properly either. When I use suggested
coding, which is same as I was usuing, as control source for the control on
my envelope, I get following two strange situations.
If zipcode is all 9 digits, and I use format 00000\-0000, then I get correct
result.But if zipcode is only 5 digits, then I get result like "00001-0598"
for zipcode that should read "10598".
If I use 00000\-9999, then this works right for 5-digit code, but
gives"782659769-9999 for 9-digit code.
I find that to bypass the problem, I'm using :
If Len(DLookup("[Zip]", "Insaddresses", "[AddIndex] = " & [AddIndex])) =5
Then
Me.Zip = DLookup(DLookup("[Zip]", "Insaddresses", " [AddIndex] = " &
[AddIndex])
ElseIf Len(DLookup("[Zip]", "Insaddresses", "[AddIndex] = " & [AddIndex])) =
9 Then
Me.Zip = DLookup(Format(DLookup("[Zip]", "Insaddresses", " [AddIndex] = " &
[AddIndex]), "00000\-0000")
End if
The above works, but I still can't figure out the problem with my table data
which causes the confusion.
Jim Burke in Novi said:
Without being able to look at your tables and your code I can't tell you why
you'd get that erratic behavior, but if you print the zip codes using the
Format I showed it should work every time - like I said, InputMask is only
for input/display on a form, it doiesn't have any effect when printing a
report. Try the format and see what happens. Normally with a nine digit zip
code you would define a text field with a length of 9 and with your Input
mask, then when printing you would use the Format function as I showed it. Is
it possible that you had some zip codes defined before you had the input mask
defined and some were entered with a '-'?
:
Jim, maybe you didn't understand what i meant by erratic behavior. the
hyphen appears in the zip code when printed for some addresses, and it
doesn't for others.
MW
:
Input mask doesn't work for printing purposes, only for data entry. If you
want them to print that way, use the Format function:
Format(DLookup("[Zip]", "Insaddresses", " [AddIndex] = " &
[AddIndex]),"00000-9999")
:
I have table with ZipCodes, whech have InputMask = "00000\-9999" .
When I try to print the zipcode on an envelope, it is erratically appearing
without the hyphen in the 9 digit code.
My code for printing is:
DLookup("[Zip]", "Insaddresses", " [AddIndex] = " & [AddIndex])
All of codes are entered by means of controls on data entry forms whose
InputMask is the same as mentioned above
Anyone have any idea why this erratic behavior, or how to correct?