G
Guest
Help, Please!
I have two issues with exisiting code and I can't figure out how to make the
pain end. I've included the NameCheck code snippet below and would really
appreciate some advice.
If I enter a DonorType of "CU" or "IN", I want to run some checks on the
FirstName and LastName. If the DonorType is "BU", I have a company name, but
may not have a FirstName and LastName so I don't want to run NameCheck
1) MINOR: if the person is DonorType "CU" or "IN" and I trigger other
message boxes in the code (such as you forgot to enter the MemberType), the
NameCheck code runs again, I suppose because it's still considered a new
record. Is there anyway to say just run the NameCheck code once?
2) WAY MAJOR: if the person is DonorType "BU", I don't have to enter the
FirstName and LastName. All seems well until I try to enter the next record
as, say, "IN". Then I land in a horrible debug loop where it seems the code
is trying to check the non-existent name in the "BU" record even though I'm
in the "IN" record:
run time error '3464:
Date type mismatch in criteria expression
And when I click on debug, it takes me to this line:
Set rst = DBEngine(0)(0).OpenRecordset("SELECT LastName,
FirstName FROM " & _
"Contacts WHERE Soundex([LastName]) = '" & _
Soundex(Me.LastName) & "'")
Private Sub Form_BeforeUpdate(Cancel As Integer)
If (DonorType) = "CU" Or (DonorType) = "IN" Then
Dim varID As Variant
Dim rst As DAO.Recordset, strNames As String
Dim gstrAppTitle As String
gstrAppTitle = "Name Check"
' 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 = DBEngine(0)(0).OpenRecordset("SELECT LastName,
FirstName FROM " & _
"Contacts 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(" There are members with similar " & "last
names already saved in the database: " & vbCrLf & vbCrLf & _
strNames & vbCrLf & "Are you sure this member is not a
duplicate?", _
vbQuestion + vbYesNo + vbDefaultButton2, gstrAppTitle)
Then
' Cancel the save
Cancel = True
End If
End If
End If
End If
End If
I have two issues with exisiting code and I can't figure out how to make the
pain end. I've included the NameCheck code snippet below and would really
appreciate some advice.
If I enter a DonorType of "CU" or "IN", I want to run some checks on the
FirstName and LastName. If the DonorType is "BU", I have a company name, but
may not have a FirstName and LastName so I don't want to run NameCheck
1) MINOR: if the person is DonorType "CU" or "IN" and I trigger other
message boxes in the code (such as you forgot to enter the MemberType), the
NameCheck code runs again, I suppose because it's still considered a new
record. Is there anyway to say just run the NameCheck code once?
2) WAY MAJOR: if the person is DonorType "BU", I don't have to enter the
FirstName and LastName. All seems well until I try to enter the next record
as, say, "IN". Then I land in a horrible debug loop where it seems the code
is trying to check the non-existent name in the "BU" record even though I'm
in the "IN" record:
run time error '3464:
Date type mismatch in criteria expression
And when I click on debug, it takes me to this line:
Set rst = DBEngine(0)(0).OpenRecordset("SELECT LastName,
FirstName FROM " & _
"Contacts WHERE Soundex([LastName]) = '" & _
Soundex(Me.LastName) & "'")
Private Sub Form_BeforeUpdate(Cancel As Integer)
If (DonorType) = "CU" Or (DonorType) = "IN" Then
Dim varID As Variant
Dim rst As DAO.Recordset, strNames As String
Dim gstrAppTitle As String
gstrAppTitle = "Name Check"
' 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 = DBEngine(0)(0).OpenRecordset("SELECT LastName,
FirstName FROM " & _
"Contacts 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(" There are members with similar " & "last
names already saved in the database: " & vbCrLf & vbCrLf & _
strNames & vbCrLf & "Are you sure this member is not a
duplicate?", _
vbQuestion + vbYesNo + vbDefaultButton2, gstrAppTitle)
Then
' Cancel the save
Cancel = True
End If
End If
End If
End If
End If