J
JK
Could someone take a look at this code and maybe locate why I'm getting error
on the rst.movenext command? This is from the Law Track example and it is
supposed to give the user an error if a duplicate contact is entered... I
just get an error message saying it's too complex to evaluate.
Thx!!!
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset, strNames As String
' If on a new row,
If (Me.NewRecord = True) Then
' Check for similar name
If Not IsNothing(Me.LastName) Then
' Open a recordset to look for similar names
Set rst = CurrentDb.OpenRecordset("SELECT LastName, FirstName
FROM " & _
"Employees WHERE Soundex([LastName]) = '" & _
Soundex(Me.LastName) & "'")
' If got some similar names, issue warning message
Do Until rst.EOF
strNames = strNames & rst!LastName & ", " & rst!FirstName &
vbCrLf
rst.MoveNext
Loop
' Done with the recordset
rst.Close
Set rst = Nothing
' See if we got some similar names
If Len(strNames) > 0 Then
' Yup, issue warning
If vbNo = MsgBox("Service Department Database found contacts
with similar " & _
"last names already saved: " & vbCrLf & vbCrLf & _
strNames & vbCrLf & "Are you sure this contact is not a
duplicate?", _
vbQuestion + vbYesNo + vbDefaultButton2, gstrAppTitle)
Then
' Cancel the save
Cancel = True
End If
End If
End If
End If
End Sub
on the rst.movenext command? This is from the Law Track example and it is
supposed to give the user an error if a duplicate contact is entered... I
just get an error message saying it's too complex to evaluate.
Thx!!!
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset, strNames As String
' If on a new row,
If (Me.NewRecord = True) Then
' Check for similar name
If Not IsNothing(Me.LastName) Then
' Open a recordset to look for similar names
Set rst = CurrentDb.OpenRecordset("SELECT LastName, FirstName
FROM " & _
"Employees WHERE Soundex([LastName]) = '" & _
Soundex(Me.LastName) & "'")
' If got some similar names, issue warning message
Do Until rst.EOF
strNames = strNames & rst!LastName & ", " & rst!FirstName &
vbCrLf
rst.MoveNext
Loop
' Done with the recordset
rst.Close
Set rst = Nothing
' See if we got some similar names
If Len(strNames) > 0 Then
' Yup, issue warning
If vbNo = MsgBox("Service Department Database found contacts
with similar " & _
"last names already saved: " & vbCrLf & vbCrLf & _
strNames & vbCrLf & "Are you sure this contact is not a
duplicate?", _
vbQuestion + vbYesNo + vbDefaultButton2, gstrAppTitle)
Then
' Cancel the save
Cancel = True
End If
End If
End If
End If
End Sub