hey ken,
there were a couple of add'l places in my form where this sort of msgbox
command was needed. i am trying to adapt your rewrite for it and it's
coughing; can you find where the bug is:
Private Sub DeleteRecord_DblClick(Cancel As Integer)
On Error GoTo Err_DeleteRecord_Click
If Me.Continuing.Value = "Yes" And vbOK = MsgBox("Be advised YOU ARE ABOUT
TO IRRETRIEVABLY DELETE AN AE which continues past this Patient's (#" &
Me![Patient Number] & ") current cycle.", vbCritical + vbOKCancel +
vbDefaultButton2, "Critical") Then
Me.AllowDeletions = True
RunCommand acCmdDeleteRecord
ElseIf Me.Continuing.Value = "Yes" And vbCancel = MsgBox("Be advised YOU
ARE
ABOUT TO IRRETRIEVABLY DELETE AN AE which continues past this Patient's
(#" &
Me![Patient Number] & ") current cycle.", vbCritical + vbOKCancel +
vbDefaultButton2, "Critical") Then
GoTo Continue:
ElseIf Me.Continuing.Value = "No" And vbOK = MsgBox("Be advised YOU ARE
ABOUT TO IRRETRIEVABLY DELETE AN AE of this Patient's (#" & Me![Patient
Number] & ") from the current cycle.", vbCritical + vbOKCancel +
vbDefaultButton2, "Critical") Then
Me.AllowDeletions = True
RunCommand acCmdDeleteRecord
ElseIf Me.Continuing.Value = "No" And vbCancel = MsgBox("Be advised YOU
ARE
ABOUT TO IRRETRIEVABLY DELETE AN AE of this Patient's (#" & Me![Patient
Number] & ") from the current cycle.", vbCritical + vbOKCancel +
vbDefaultButton2, "Critical") Then
GoTo Continue:
End If
Continue:
Exit_DeleteRecord_Click:
Me.AllowDeletions = False
Exit Sub
Err_DeleteRecord_Click:
'Ignore "error" if user cancels delete; otherwise
' show the error message.
If Err.Number <> 2501 Then
MsgBox Err.description
End If
Resume Exit_DeleteRecord_Click
End Sub
Ken Snell said:
I believe it's because of this step in your original code:
ElseIf Response = 2 Then GoTo Start2
To be correct, it should have been two code steps:
ElseIf Response = 2 Then
GoTo Start2
I provided the rewrite to show how to use a more logical flow for the
code;
not the old BASIC GoTo actions, but rather the more desired
If..Then...Else
structure.
--
Ken Snell
<MS ACCESS MVP>
but of course.....
and it looks like a winner; but what's the lesson underlying the code
here?
why does it work and mine not (apart from my being newbie)?
-ted
:
May I suggest a slight rewrite of your code?
Private Sub DeleteRecord_DblClick(Cancel As Integer)
On Error GoTo Err_DeleteRecord_Click
If vbOK = MsgBox("Be advised you are about to IRREVERSIBLY DELETE ALL
records of this patient's (#" & _
Me![Patient Number] & ") in this cycle! This may result in the
deletion
of an AE which continues past the current cycle, i.e. Cycle #" & _
Me.[Current Cycle Number] & " !" _
& " Moreover, be advised that upon succesful deletion of this
cycle's
data, there may be AEs listed as continuing past the preceding one
requiring
your attention!", vbCritical + vbOKCancel, "Critical") Then
Me.AllowDeletions = True
RunCommand acCmdDeleteRecord
End If
Exit_DeleteRecord_Click:
Me.AllowDeletions = False
Exit Sub
Err_DeleteRecord_Click:
'Ignore "error" if user cancels delete; otherwise
' show the error message.
If Err.Number <> 2501 Then
MsgBox Err.description
End If
Resume Exit_DeleteRecord_Click
End Sub
--
Ken Snell
<MS ACCESS MVP>
wouldn't you know it, i forgot to copy the vba code into my posting:
Private Sub DeleteRecord_DblClick(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("Be advised you are about to IRREVERSIBLY DELETE
ALL
records of this patient's (#" & Me![Patient Number] & ") in this
cycle!
This
may result in the deletion of an AE which continues past the current
cycle,
i.e. Cycle #" & Me.[Current Cycle Number] & " !" _
& " Moreover, be advised that upon succesful deletion of this
cycle's
data,
there may be AEs listed as continuing past the preceding one
requiring
your
attention!", 17, "Critical")
If Response = 1 Then
GoTo Start1
ElseIf Response = 2 Then GoTo Start2
End If
On Error GoTo Err_DeleteRecord_Click
Start1:
Me.AllowDeletions = True
RunCommand acCmdDeleteRecord
Exit_DeleteRecord_Click:
Me.AllowDeletions = False
Exit Sub
Err_DeleteRecord_Click:
'Ignore "error" if user cancels delete; otherwise
' show the error message.
If Err.Number <> 2501 Then
MsgBox Err.description
End If
Resume Exit_DeleteRecord_Click
Start2:
End Sub
please excuse..
:
as you can see from my humble vba code below, i want to tell the
user
that
something really serious is about to happen if they proceed on
their
selected
path.
the system generates a message that's also informative, but i want
to
make
really really sure that the user 'gets it'. in testing my code, i
have
found
that when i click the ok from my message prompt and then click 'No'
from
the
system's generated message that i get a message box telling me 'The
RunCommand Action Was Canceled', 'Runtime Error 2501'. when i
attempt
to
debug it, the following line in the vba code is highlighted in
yellow:
RunCommand acCmdDeleteRecord
anyone got a clue why this is happening to this vba newbie?