Here is the code, I even changed to check for the value but it is doing the same:
Private Sub cmdCheckAddress_Click()
' ** NOTE Variable Names Are being duplicated from documentation.
Dim hUnz As Long
Dim szFirmName As String * 51 ' ** All Fixed Sized Are To 51 Default
Dim szPRUrb As String * 51
Dim szDelLine As String * 51
Dim szLastLine As String * 51
Dim szCity As String * 51
Dim szState As String * 51
Dim szZIP As String * 51
Dim szCOUNTY As String * 51
Dim szAREACODE As String * 51
Dim Result As Long
Dim Line1 As String, line2 As String, line3 As String, Line4 As String
' First open the DLL. Bail out if this fails...
hUnz = UNZ_INIT_EX()
If hUnz = 0 Then 'OOps...someting is wrong...
MsgBox "DLL initialization failed"
Forms!frmApplicantDataEntry![SSN].SetFocus
Exit Sub
End If
' MsgBox "DLL Init okay"
' If we get here, the DLL is open and ready to check an address
' Next, prepare the 4 address parameters for UNZ_CHECKADDRESS()
If Address.Value = 0 Then
Line1 = "" ' no firm name
line2 = "" ' no Puerto Rico addresses in the demo
line3 = StreetAddress ' this is the street address
Line4 = City & ", " & State & " " & Zip ' build city-st-zip
Else
Line1 = "" ' no firm name
line2 = "" ' no Puerto Rico addresses in the demo
line3 = ShipAddress ' this is the street address
Line4 = ShipCity & ", " & ShipState & " " & ShipZipCode ' build city-st-zip
End If
' Call the DLL to check the address and get the result code
Result = UNZ_CHECKADDRESS(hUnz, Line1, line2, line3, Line4)
' MsgBox "Check Address result = " & Result
' Examine the result code to determine what happened
Select Case Result
Case XC_GOODADDR ' The address was just fine the way it was...
' MsgBox "Address found - no changes necessary"
Case XC_ZIP To XC_5DIG ' The address was corrected
' MsgBox "Address found and corrected"
' Here we get the corrected address strings from the DLL
' First we get the original strings, corrected as necessary
If Address.Value = 0 Then
Result = UNZ_GETSTDADDRESS(hUnz, szFirmName, szPRUrb, szDelLine, szLastLine)
StreetAddress = FixedToVar(szDelLine)
Else
Result = UNZ_GETSTDADDRESS(hUnz, szFirmName, szPRUrb, szDelLine, szLastLine)
ShipAddress = FixedToVar(szDelLine)
End If
' City-ST-ZIP are already in szLastLine, but we need them as separate strings
If Address.Value = 0 Then
Result = UNZ_GETCITY(hUnz, szCity)
City = FixedToVar(szCity)
Result = UNZ_GETSTATE(hUnz, szState)
State = FixedToVar(szState)
Result = UNZ_GETZIP(hUnz, szZIP)
Zip = FixedToVar(szZIP)
Else
Result = UNZ_GETCITY(hUnz, szCity)
ShipCity = FixedToVar(szCity)
Result = UNZ_GETSTATE(hUnz, szState)
ShipState = FixedToVar(szState)
Result = UNZ_GETZIP(hUnz, szZIP)
ShipZipCode = FixedToVar(szZIP)
End If
'County
If Address.Value = 0 Then
Result = UNZ_CHECKADDRESS(hUnz, szFirmName, szPRUrb, szDelLine, szLastLine)
County = FixedToVar(szDelLine)
Result = UNZ_GETCOUNTY(hUnz, szCOUNTY)
County = FixedToVar(szCOUNTY)
Else
Result = UNZ_CHECKADDRESS(hUnz, szFirmName, szPRUrb, szDelLine, szLastLine)
ShipCounty = FixedToVar(szDelLine)
Result = UNZ_GETCOUNTY(hUnz, szCOUNTY)
ShipCounty = FixedToVar(szCOUNTY)
End If
Case XC_MULT ' Multiple matching addresses were found
MsgBox "Multiple matching addresses found"
Case XC_BADADDR To XC_FHERR ' The address (or city-st-ZIP) is invalid
MsgBox "Address was not found"
Case Else
MsgBox "An internal error occurred during the address check"
End Select
' Close the DLL, ignore the result
Result = UNZ_TERM(hUnz)
' Move focus back to first field...
Forms!frmApplicantDataEntry![Home Phone].SetFocus
End Sub