hello all...
I'm having a data type mismatch error on a piece of code that worked fine one minute and gave me an error the next. It is testing for duplicate names. It's driving me crazy. The associated modules work just fine. Here is the code
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset, strNames As String
The error is in this piece.
Set rst = CurrentDb.OpenRecordset("SELECT txtLastName, txtFirstName FROM " & _
Any ideas???? The only thing I can think of is that I moved the txtFirstName and txtLastName from the form to a tab control. Would this matter?
sorry if this is a Noob question... I'm re-teaching myself VB after about five years.
Thanks.
I'm having a data type mismatch error on a piece of code that worked fine one minute and gave me an error the next. It is testing for duplicate names. It's driving me crazy. The associated modules work just fine. Here is the code
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.txtLastName) Then
' Open a recordset to look for similar names
Set rst = CurrentDb.OpenRecordset("SELECT txtLastName, txtFirstName FROM " & _
"tblEmployeeEntry WHERE Soundex([txtLastName]) = '" & _
Soundex(Me.txtLastName) & "'")
' If got some similar names, issue warning message
Do Until rst.EOF
strNames = strNames & rst!txtLastName & ", " & rst!txtFirstName & 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("Found employee with similar " & _
"last name already saved in the database: " & vbCrLf & vbCrLf & _
strNames & vbCrLf & "Are you sure this person is not a duplicate?", _
vbQuestion + vbYesNo + vbDefaultButton2, gstrAppTitle) Then
' Cancel the save
Cancel = True
End If
End If
End If
End If
End SubThe error is in this piece.
Set rst = CurrentDb.OpenRecordset("SELECT txtLastName, txtFirstName FROM " & _
"tblEmployeeEntry WHERE Soundex([txtLastName]) = '" & _
Soundex(Me.txtLastName) & "'")
Any ideas???? The only thing I can think of is that I moved the txtFirstName and txtLastName from the form to a tab control. Would this matter?
sorry if this is a Noob question... I'm re-teaching myself VB after about five years.
Thanks.