D
Doctor
On strContact I keep getting a type mismatch error and I'm not sure why.
Below I pasted the code performing the DLookup and also the SQL for the query
the DLookup is searching. Me.ContactChurch is a combo box in the form and
Me.ContactLastName is a text box in the form.
What the code is doing on frmContactAdd is searching to see if someone from
the same church exists with the same last name and if so it asks the user if
they want to add that persons information into the form.
Thanks in advance.
FORM CODE
Dim strContact As String
Dim strMsg As String
Dim strAddress1, strAddress2, strCity, strStateID, strState, strZip,
strPhone As String
strContact = DLookup("ContactID", "qryLLCAddressFillIn", "[ChurchID]=" &
Me.ContactChurch.Value And " [ContactLastName]=" & Me.ContactLastName.Value)
strAddress1 = DLookup("ContactAddress1", "qryLLCAddressFillIn",
"[ContactID]=" & strContact)
strAddress2 = DLookup("ContactAddress2", "qryLLCAddressFillIn",
"[ContactID]=" & strContact)
strCity = DLookup("ContactCity", "qryLLCAddressFillIn", "[ContactID]=" &
strContact)
strStateID = DLookup("ContactState", "qryLLCAddressFillIn",
"[ContactID]=" & strContact)
strPhone = DLookup("ContactZip", "qryLLCAddressFillIn", "[ContactID]=" &
strContact)
strState = DLookup("StateAbb", "State", "[ID]=" & strStateID)
strMsg = "A contact was found from this church with the same last name.
Chr(13) Chr(13)" & _
"Would you like to use their address? Chr(13) Chr(13)" & _
"" & strAddress1 & "Chr(13)" & _
"" & strCity & ", " & strState & " " & strZip & "Chr(13)" & _
"" & strPhone & ""
Debug.Print strContact
If Not IsNothing(strContact) Then
If MsgBox(strMsg, vbYesNo, "Add Address") = vbYes Then
Me.ContactAddress1.Value = strAddress1
Me.ContactAddress2.Value = strAddress2
Me.ContactCity.Value = strCity
Me.ContactState.Value = strStateID
Me.ContactZip.Value = strZip
Me.ContactEmail.SetFocus
End If
End If
SQL CODE
SELECT Contacts.ContactLastName, Contacts.ContactID, Church.ChurchID,
Contacts.ContactChurch, Contacts.ContactAddress1, Contacts.ContactAddress2,
Contacts.ContactCity, Contacts.ContactState, Contacts.ContactZip,
Contacts.ContactPhone
FROM Church INNER JOIN Contacts ON Church.ChurchID = Contacts.ContactChurch
GROUP BY Contacts.ContactLastName, Contacts.ContactID, Church.ChurchID,
Contacts.ContactChurch, Contacts.ContactAddress1, Contacts.ContactAddress2,
Contacts.ContactCity, Contacts.ContactState, Contacts.ContactZip,
Contacts.ContactPhone
HAVING (((Contacts.ContactAddress1) Is Not Null))
ORDER BY Contacts.ContactLastName;
Below I pasted the code performing the DLookup and also the SQL for the query
the DLookup is searching. Me.ContactChurch is a combo box in the form and
Me.ContactLastName is a text box in the form.
What the code is doing on frmContactAdd is searching to see if someone from
the same church exists with the same last name and if so it asks the user if
they want to add that persons information into the form.
Thanks in advance.
FORM CODE
Dim strContact As String
Dim strMsg As String
Dim strAddress1, strAddress2, strCity, strStateID, strState, strZip,
strPhone As String
strContact = DLookup("ContactID", "qryLLCAddressFillIn", "[ChurchID]=" &
Me.ContactChurch.Value And " [ContactLastName]=" & Me.ContactLastName.Value)
strAddress1 = DLookup("ContactAddress1", "qryLLCAddressFillIn",
"[ContactID]=" & strContact)
strAddress2 = DLookup("ContactAddress2", "qryLLCAddressFillIn",
"[ContactID]=" & strContact)
strCity = DLookup("ContactCity", "qryLLCAddressFillIn", "[ContactID]=" &
strContact)
strStateID = DLookup("ContactState", "qryLLCAddressFillIn",
"[ContactID]=" & strContact)
strPhone = DLookup("ContactZip", "qryLLCAddressFillIn", "[ContactID]=" &
strContact)
strState = DLookup("StateAbb", "State", "[ID]=" & strStateID)
strMsg = "A contact was found from this church with the same last name.
Chr(13) Chr(13)" & _
"Would you like to use their address? Chr(13) Chr(13)" & _
"" & strAddress1 & "Chr(13)" & _
"" & strCity & ", " & strState & " " & strZip & "Chr(13)" & _
"" & strPhone & ""
Debug.Print strContact
If Not IsNothing(strContact) Then
If MsgBox(strMsg, vbYesNo, "Add Address") = vbYes Then
Me.ContactAddress1.Value = strAddress1
Me.ContactAddress2.Value = strAddress2
Me.ContactCity.Value = strCity
Me.ContactState.Value = strStateID
Me.ContactZip.Value = strZip
Me.ContactEmail.SetFocus
End If
End If
SQL CODE
SELECT Contacts.ContactLastName, Contacts.ContactID, Church.ChurchID,
Contacts.ContactChurch, Contacts.ContactAddress1, Contacts.ContactAddress2,
Contacts.ContactCity, Contacts.ContactState, Contacts.ContactZip,
Contacts.ContactPhone
FROM Church INNER JOIN Contacts ON Church.ChurchID = Contacts.ContactChurch
GROUP BY Contacts.ContactLastName, Contacts.ContactID, Church.ChurchID,
Contacts.ContactChurch, Contacts.ContactAddress1, Contacts.ContactAddress2,
Contacts.ContactCity, Contacts.ContactState, Contacts.ContactZip,
Contacts.ContactPhone
HAVING (((Contacts.ContactAddress1) Is Not Null))
ORDER BY Contacts.ContactLastName;