I have some basic code that performs a task as long as the Record Count > 0. However, if the record it is using does not contain a valid number in one of the fields then for some reason the Record Count = 0.
Below is the section of code in question. Specifically, if the SupvEmail is null or 0,the Record Count = 0 and then the code skips down to the ELSE MsgBox.
/CODE
With rstEmail
If .RecordCount > 0 Then
If GenlInfo.Contact = "" Then
Call GetGenlInfo
GenlInfo = ggiGenlInfo
End If
Do While Not .EOF
' Check for missing data
' Verify email address exists in the table
If Nz(.Fields("StaffEmail"
) = "" Then
MsgBox "Cardholder '" & .Fields("StaffFName"
& " " & .Fields("StaffLName"
& _
"' does not have an email address in the table." & vbCrLf & _
"Use Staff Maintenance form to add the cardholder's email address" & _
" and then try again to email the findings.", vbInformation = vbOKOnly, _
"Missing Email Address"
Exit Sub
Else
strTo = .Fields("StaffEmail"
' Supervisor email address
If Nz(.Fields("SpvsrEmail"
) = "" Then
strCC = GenlInfo.ContactEmail
Else
strCC = .Fields("SpvsrEmail"
End If
... <snip emailing code for brevity>
End If 'missing email address
.MoveNext
Loop
MsgBox "Emails have been sent to cardholders", , "Email Sent"
Else
MsgBox "There were no staff details for this document that have not been sent.", _
vbOKOnly + vbInformation, "No Data"
End If 'detail records exist
End With
/CODE
Although the SupvEmail doesn't contain a number, there IS a record there, so I don't understand why Record Count = 0.
TIA for any ideas or help.
KerryL
Below is the section of code in question. Specifically, if the SupvEmail is null or 0,the Record Count = 0 and then the code skips down to the ELSE MsgBox.
/CODE
With rstEmail
If .RecordCount > 0 Then
If GenlInfo.Contact = "" Then
Call GetGenlInfo
GenlInfo = ggiGenlInfo
End If
Do While Not .EOF
' Check for missing data
' Verify email address exists in the table
If Nz(.Fields("StaffEmail"
MsgBox "Cardholder '" & .Fields("StaffFName"
"' does not have an email address in the table." & vbCrLf & _
"Use Staff Maintenance form to add the cardholder's email address" & _
" and then try again to email the findings.", vbInformation = vbOKOnly, _
"Missing Email Address"
Exit Sub
Else
strTo = .Fields("StaffEmail"
' Supervisor email address
If Nz(.Fields("SpvsrEmail"
strCC = GenlInfo.ContactEmail
Else
strCC = .Fields("SpvsrEmail"
End If
... <snip emailing code for brevity>
End If 'missing email address
.MoveNext
Loop
MsgBox "Emails have been sent to cardholders", , "Email Sent"
Else
MsgBox "There were no staff details for this document that have not been sent.", _
vbOKOnly + vbInformation, "No Data"
End If 'detail records exist
End With
/CODE
Although the SupvEmail doesn't contain a number, there IS a record there, so I don't understand why Record Count = 0.
TIA for any ideas or help.
KerryL