D
Doctor
I am trying to do a comparison between a query and a table. And one of the
comparison fields is the Postal Code field. But somehow this is not working
the way that I expect.
I have a function (pasted below) that takes a postal code and formats it so
that both tables have the same format to them for comparison
My query is based on a table and a query. I have forced the zip code in both
to be a string with CStr(). But still get the error. I have tried many
variations of my query. What am I missing?
My query:
SELECT ztblImportChurches.ImportID, *
FROM ztblImportChurches
WHERE (((ztblImportChurches.ImportID) In (SELECT ztblImportChurches.ImportID
FROM ztblImportChurches INNER JOIN zqryImportChurches1 ON
((ztblImportChurches.ChurchName = zqryImportChurches1.ChurchName)
OR (ztblImportChurches.ChurchName Is Null AND
zqryImportChurches1.ChurchName Is Null)) AND
((CStr(FormatZipFirst([ztblImportChurches].[Zip])) =
CStr([zqryImportChurches1].[ZipCode])) OR (ztblImportChurches.Zip Is Null AND
zqryImportChurches1.ZipCode Is Null))
GROUP BY ztblImportChurches.ImportID)));
My Function:
Function FormatZipFirst(sCode As String) As String
'Gets the first characters of USA and Canada Postal Codes properly formated
If sCode Like "#####" Then 'USA
FormatZipFirst = sCode
ElseIf sCode Like "#####-####" Then
FormatZipFirst = Left(sCode, 5)
ElseIf sCode Like "#####-" Then
FormatZipFirst = Left(sCode, 5)
ElseIf sCode Like "[A-Z]#[A-Z] #[A-Z]#" Then 'Canada Zips
FormatZipFirst = sCode
ElseIf sCode Like "[A-Z]#[A-Z]#[A-Z]#" Then
FormatZipFirst = Left(sCode, 3) & " " & Mid(sCode, 4, 3)
Else
FormatZipFirst = sCode
End If
End Function
Thanks in advance for the help.
comparison fields is the Postal Code field. But somehow this is not working
the way that I expect.
I have a function (pasted below) that takes a postal code and formats it so
that both tables have the same format to them for comparison
My query is based on a table and a query. I have forced the zip code in both
to be a string with CStr(). But still get the error. I have tried many
variations of my query. What am I missing?
My query:
SELECT ztblImportChurches.ImportID, *
FROM ztblImportChurches
WHERE (((ztblImportChurches.ImportID) In (SELECT ztblImportChurches.ImportID
FROM ztblImportChurches INNER JOIN zqryImportChurches1 ON
((ztblImportChurches.ChurchName = zqryImportChurches1.ChurchName)
OR (ztblImportChurches.ChurchName Is Null AND
zqryImportChurches1.ChurchName Is Null)) AND
((CStr(FormatZipFirst([ztblImportChurches].[Zip])) =
CStr([zqryImportChurches1].[ZipCode])) OR (ztblImportChurches.Zip Is Null AND
zqryImportChurches1.ZipCode Is Null))
GROUP BY ztblImportChurches.ImportID)));
My Function:
Function FormatZipFirst(sCode As String) As String
'Gets the first characters of USA and Canada Postal Codes properly formated
If sCode Like "#####" Then 'USA
FormatZipFirst = sCode
ElseIf sCode Like "#####-####" Then
FormatZipFirst = Left(sCode, 5)
ElseIf sCode Like "#####-" Then
FormatZipFirst = Left(sCode, 5)
ElseIf sCode Like "[A-Z]#[A-Z] #[A-Z]#" Then 'Canada Zips
FormatZipFirst = sCode
ElseIf sCode Like "[A-Z]#[A-Z]#[A-Z]#" Then
FormatZipFirst = Left(sCode, 3) & " " & Mid(sCode, 4, 3)
Else
FormatZipFirst = sCode
End If
End Function
Thanks in advance for the help.