G
Guest
I'm setting up inline error handling for inserting new
records into a table to catch duplicates on a SSN field.
For some reason, on execution of my sqlError Sub, it does
not execute the code after the Select Statement. Why is
that happeneing? Instead, it jumps back to after the call
and then exits from the orignial Sub.
--- code snipped ----
On Error Resume Next
thisRS.Open "tblPatient", Main.myCnxn, adOpenKeyset, _
adLockOptimistic, adCmdTable
thisRS.AddNew
thisRS!ssn = txtSSN.Value
thisRS!f_name = txtFirst.Value
thisRS!m_name = txtMiddle.Value
thisRS!l_name = txtLast.Value
thisRS.Update
'Check for previous patient entry and exit if exists
If Err.Number = -2147217887 Then
Call sqlError(Main.errINSERT, "SSN", txtSSN.Value)
Err.Clear 'Clear out Error
Exit Sub
Else
'Get new Patient ID to be able to add case
Main.patientID = thisRS!id
End If
--- code snipped ----
---------------------
Private Sub sqlError(errType As Integer, errField As
String, Optional errFieldVal As Variant)
Dim thisError As String
Select Case errType
Case Main.errINSERT
thisError = "There is an existing record for the" _
& "field " & errField & " with value " _
& CStr(errFieldVal) & "!"
lblStatus.Caption = "Record was not added to the" _
& "database."
cmdSave.Enabled = False
Case Main.errDELETE
Case Main.errUPDATE
End Select
thisError = thisError & vbCrLf & "Can not add record!"
MsgBox thisError, vbCritical, "ERROR"
End Sub
records into a table to catch duplicates on a SSN field.
For some reason, on execution of my sqlError Sub, it does
not execute the code after the Select Statement. Why is
that happeneing? Instead, it jumps back to after the call
and then exits from the orignial Sub.
--- code snipped ----
On Error Resume Next
thisRS.Open "tblPatient", Main.myCnxn, adOpenKeyset, _
adLockOptimistic, adCmdTable
thisRS.AddNew
thisRS!ssn = txtSSN.Value
thisRS!f_name = txtFirst.Value
thisRS!m_name = txtMiddle.Value
thisRS!l_name = txtLast.Value
thisRS.Update
'Check for previous patient entry and exit if exists
If Err.Number = -2147217887 Then
Call sqlError(Main.errINSERT, "SSN", txtSSN.Value)
Err.Clear 'Clear out Error
Exit Sub
Else
'Get new Patient ID to be able to add case
Main.patientID = thisRS!id
End If
--- code snipped ----
---------------------
Private Sub sqlError(errType As Integer, errField As
String, Optional errFieldVal As Variant)
Dim thisError As String
Select Case errType
Case Main.errINSERT
thisError = "There is an existing record for the" _
& "field " & errField & " with value " _
& CStr(errFieldVal) & "!"
lblStatus.Caption = "Record was not added to the" _
& "database."
cmdSave.Enabled = False
Case Main.errDELETE
Case Main.errUPDATE
End Select
thisError = thisError & vbCrLf & "Can not add record!"
MsgBox thisError, vbCritical, "ERROR"
End Sub