Thank you for the prompt responses!
The chr(34) should work; how did you use it? It would get concatenated into the string.
This gives me a type mismatch error, as does using chr(39):
Code:
Private Sub CmdAdd_Click()On Error GoTo Err_CmdAdd_Click
If DCount("*", "Contact_Info", "Last_Name= " & Chr(34) & Me.Last_Name & Chr(34) And "First_Name=" & Chr(34) & Me.First_Name & Chr(34)) > 0 Then
msgbox "This contact already exists!", vbOK, "Duplicate Entry!"
Me.Undo
Exit Sub
Wouldn't this be better/easier if the name(s) were displayed in combo boxes? Not in the list = not in the table.
I have done this before in other databases I have created so I wanted to expand my knowledge a bit and try something harder... maybe too hard??
Originally Posted by
Micron
This appears to work with Red's assigned to the variable strWord:
DCount("*", "fieldName", "tableName=""" & strWord & """")
The issue appears to be when I try to concatenate the two criteria into a single Dcount statement. I need to do this so that Contacts with the same last name but different first names are accepted but Contacts with the same first name and the same last name trigger clearing the form.
This works (but only on the last name):
Code:
Private Sub CmdAdd_Click()On Error GoTo Err_CmdAdd_Click
Dim strwordF As String
Dim strwordL As String
strwordF = Me.First_Name.Value
strwordL = Me.Last_Name.Value
If DCount("*", "Contact_Info", "Last_Name=""" & strwordL & """" ) > 0 Then
msgbox "This contact already exists!", vbOK, "Duplicate Entry!"
Me.Undo
Exit Sub
This fails by giving me a Type mismatch error:
Code:
Private Sub CmdAdd_Click()On Error GoTo Err_CmdAdd_Click
Dim strwordF As String
Dim strwordL As String
strwordF = Me.First_Name.Value
strwordL = Me.Last_Name.Value
If DCount("*", "Contact_Info", "Last_Name=""" & strwordL & """" And "First_Name= """ & strwordF & """") > 0 Then
msgbox "This contact already exists!", vbOK, "Duplicate Entry!"
Me.Undo
Exit Sub