K
Kurt
I am trying to handle a record delete through a SQL
statement.
The delete works except:
1. "#Deleted" appears in all the affected fields until I
close and reopen the database. I obviously need some sort
of refresh statement.
2. Even though the delete ultimately worked, my custom
msgbox, "There were no records to update.", which is part
of an If Then statement near the end of the code,
executes. This is probably related to #1 above.
Any ideas? Thanks. - Kurt (Code below)
###
Private Sub cmdDeleteMI_Click()
On Error GoTo Err_Cancel
Dim iresponse As Integer
iresponse = MsgBox("This will delete this patient's
medical intake record, as well as any exam(s) associated
with this record." & _
Chr(13) & Chr(13) & "Continue?", 4 + 32 + 256)
If iresponse = 7 Then
Exit Sub
Else
End If
Dim db As DAO.Database
Set db = CurrentDb
Dim StrSql As String
StrSql = "DELETE tblMedicalIntake.intCaseNumber " & _
"FROM tblMedicalIntake " & _
"WHERE (((tblMedicalIntake.intCaseNumber)=[Forms]!
[frmMedicalIntake]![txtCaseNumber]));"
DoCmd.RunSQL StrSql
If db.RecordsAffected > 0 Then
'Tell user query was completed
MsgBox "Operation completed. Updated " &
db.RecordsAffected & " Records"
Else
MsgBox "There were no records to update."
End If
Set db = Nothing
Exit_Cancel: ' Label to resume after error.
Exit Sub ' Exit before error handler.
Err_Cancel: ' Label to jump to on error.
MsgBox Err.Number & Err.Description ' Place error
handling here.
Resume Exit_Cancel
Exit_cmdDeleteMI_Click:
Exit Sub
End Sub
statement.
The delete works except:
1. "#Deleted" appears in all the affected fields until I
close and reopen the database. I obviously need some sort
of refresh statement.
2. Even though the delete ultimately worked, my custom
msgbox, "There were no records to update.", which is part
of an If Then statement near the end of the code,
executes. This is probably related to #1 above.
Any ideas? Thanks. - Kurt (Code below)
###
Private Sub cmdDeleteMI_Click()
On Error GoTo Err_Cancel
Dim iresponse As Integer
iresponse = MsgBox("This will delete this patient's
medical intake record, as well as any exam(s) associated
with this record." & _
Chr(13) & Chr(13) & "Continue?", 4 + 32 + 256)
If iresponse = 7 Then
Exit Sub
Else
End If
Dim db As DAO.Database
Set db = CurrentDb
Dim StrSql As String
StrSql = "DELETE tblMedicalIntake.intCaseNumber " & _
"FROM tblMedicalIntake " & _
"WHERE (((tblMedicalIntake.intCaseNumber)=[Forms]!
[frmMedicalIntake]![txtCaseNumber]));"
DoCmd.RunSQL StrSql
If db.RecordsAffected > 0 Then
'Tell user query was completed
MsgBox "Operation completed. Updated " &
db.RecordsAffected & " Records"
Else
MsgBox "There were no records to update."
End If
Set db = Nothing
Exit_Cancel: ' Label to resume after error.
Exit Sub ' Exit before error handler.
Err_Cancel: ' Label to jump to on error.
MsgBox Err.Number & Err.Description ' Place error
handling here.
Resume Exit_Cancel
Exit_cmdDeleteMI_Click:
Exit Sub
End Sub