afterdelconfirm/beforedelconfirm event not working in a2k mdb

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which continues
past this cycle.", vbCritical, "Critical")
End If
End Sub
 
Please provide more info.....how is it not working, what are the intended
results, what are the actual results? Have you set toggle points in each
event to trace the flow? What were your findings?

Ozzone
 
Ted said:
can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues
past this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As
Integer) If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which
continues past this cycle.", vbCritical, "Critical")
End If
End Sub

What do you mean by "not working"? Are the event procedures not being
executed, or are you just not getting the message that your code is
intended to display?

If the event procedures aren't being executed, check these
possibilities:

+ Do you have warnings turned off? You might have done that by
unchecking the "Confirm Record changes" on the Edt/Find tab of the
Tools -> Options dialog, or by executing the VBA statement
"DoCmd.SetWarnings False".

+ Another possibility is that you don't have the form's BeforeDelConfirm
and AfterDelConfirm properties (on the Event tab of the form's property
sheet) set to "[Event Procedure]".

If the event procedures are being executed, but you're not getting the
message you expect, consider this:

+ When the form's BeforeDelConfirm event fires, the record *has already
been deleted*. You can undo that deletion if you go on to tell the
confirmation dialog you don't want to do it, but right now the record
has been deleted. Therefore, Me.[Continuing].Value no longer has the
value that it had when you initiated the delete. Instead, it has the
value that beloings to the next record in the form's recordset, or the
new blank record if you deleted the last record.

+ If you want to check a value from the record that is being deleted,
grab that value in the form's Delete event and store it in a
module-level variable. Then you can check that variable in the form's
BeforeDelConfirm and AfterDelConfirm event.
 
Ted said:
can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which continues
past this cycle.", vbCritical, "Critical")
End If
End Sub

It would help if you indicated in what way it isn't working. Do you get an
error message, and if so, what? Or, if the events don't fire at all, make
sure that "Confirm Record Changes" is ticked in Options, and that the events
in the form's property sheet are set to "[Event Procedure]"
 
well, ok....

i have two related/nested forms, main: [Treatment and Toxicity] and sub:
[Adverse Events (child)], each of which has an underlying table. the latter
is displayed nested w/in the main form as a continuous sub-form.

the idea i'm trying to implement is this: when the user is in the process
of deleting a record from the sub-form, i want the user to be alerted to the
fact that other records for the same individual/PK (which is a composite of
Patient Number, Cycle number, AE, Subtype, and Onset_Date) may need deleting.
meaning that if user is deleting a record from cycle number 1, then he
probably needs to delete corresponding records from all subsequent cycle
values for this patient since they come after it and would ogically not
belong in the db if number 1's is coded as continuing into other cycles.

i have a function in the OnDelete event already :

Public Function acbLogDelete( _
strTableName As String, varPK As Variant) As Integer

' Record deletion of a record in the
' log table

On Error GoTo HandleErr

acbLogDelete = acbLog(strTableName, varPK, mconLogDelete)

ExitHere:
Exit Function

HandleErr:
MsgBox "Error " & Err.Number & ": " & Err.description, _
, "acbLogDelete()"
Resume ExitHere
End Function

so i'm (being a virtual newbie) trying to figure out where else to put this
message and tried the before/after delete events -- no message whatsoever
appears when i tested it.

hth,

-ted


the first message to display

Ozzone said:
Please provide more info.....how is it not working, what are the intended
results, what are the actual results? Have you set toggle points in each
event to trace the flow? What were your findings?

Ozzone


Ted said:
can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which continues
past this cycle.", vbCritical, "Critical")
End If
End Sub
 
im taking a short break from the computer, so i will check out your previous
post in detail when i get back if noone has provided you with an answer.

If the DelConfirm events are not firing at all (easily checked by placing a
toggle point in the event code) then the first thing i would look at, as
Brian mentioned, is whether or not "Confirm Record Changes" is on. If its
not, niether event will fire, as stated in the VBA help file.

Ozzone


Ted said:
well, ok....

i have two related/nested forms, main: [Treatment and Toxicity] and sub:
[Adverse Events (child)], each of which has an underlying table. the latter
is displayed nested w/in the main form as a continuous sub-form.

the idea i'm trying to implement is this: when the user is in the process
of deleting a record from the sub-form, i want the user to be alerted to the
fact that other records for the same individual/PK (which is a composite of
Patient Number, Cycle number, AE, Subtype, and Onset_Date) may need deleting.
meaning that if user is deleting a record from cycle number 1, then he
probably needs to delete corresponding records from all subsequent cycle
values for this patient since they come after it and would ogically not
belong in the db if number 1's is coded as continuing into other cycles.

i have a function in the OnDelete event already :

Public Function acbLogDelete( _
strTableName As String, varPK As Variant) As Integer

' Record deletion of a record in the
' log table

On Error GoTo HandleErr

acbLogDelete = acbLog(strTableName, varPK, mconLogDelete)

ExitHere:
Exit Function

HandleErr:
MsgBox "Error " & Err.Number & ": " & Err.description, _
, "acbLogDelete()"
Resume ExitHere
End Function

so i'm (being a virtual newbie) trying to figure out where else to put this
message and tried the before/after delete events -- no message whatsoever
appears when i tested it.

hth,

-ted


the first message to display

Ozzone said:
Please provide more info.....how is it not working, what are the intended
results, what are the actual results? Have you set toggle points in each
event to trace the flow? What were your findings?

Ozzone


Ted said:
can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which continues
past this cycle.", vbCritical, "Critical")
End If
End Sub
 
dirk, how would i grab the value of the Continuing variable in the delete
event (i pasted it in my posting to Ozzone)? i am relative newbie.

with thanks,

-ted


Dirk Goldgar said:
Ted said:
can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues
past this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As
Integer) If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which
continues past this cycle.", vbCritical, "Critical")
End If
End Sub

What do you mean by "not working"? Are the event procedures not being
executed, or are you just not getting the message that your code is
intended to display?

If the event procedures aren't being executed, check these
possibilities:

+ Do you have warnings turned off? You might have done that by
unchecking the "Confirm Record changes" on the Edt/Find tab of the
Tools -> Options dialog, or by executing the VBA statement
"DoCmd.SetWarnings False".

+ Another possibility is that you don't have the form's BeforeDelConfirm
and AfterDelConfirm properties (on the Event tab of the form's property
sheet) set to "[Event Procedure]".

If the event procedures are being executed, but you're not getting the
message you expect, consider this:

+ When the form's BeforeDelConfirm event fires, the record *has already
been deleted*. You can undo that deletion if you go on to tell the
confirmation dialog you don't want to do it, but right now the record
has been deleted. Therefore, Me.[Continuing].Value no longer has the
value that it had when you initiated the delete. Instead, it has the
value that beloings to the next record in the form's recordset, or the
new blank record if you deleted the last record.

+ If you want to check a value from the record that is being deleted,
grab that value in the form's Delete event and store it in a
module-level variable. Then you can check that variable in the form's
BeforeDelConfirm and AfterDelConfirm event.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
brian,dirk:

i'm having trouble locating where the special text you're implicating is
located. i looked under all four tabs of options under tools in the vba and
don't find it.

Brian said:
Ted said:
can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which continues
past this cycle.", vbCritical, "Critical")
End If
End Sub

It would help if you indicated in what way it isn't working. Do you get an
error message, and if so, what? Or, if the events don't fire at all, make
sure that "Confirm Record Changes" is ticked in Options, and that the events
in the form's property sheet are set to "[Event Procedure]"
 
From the Access window, not the VBA editor, Tools > Options... > Find/Edit tab

Ozzone


Ted said:
brian,dirk:

i'm having trouble locating where the special text you're implicating is
located. i looked under all four tabs of options under tools in the vba and
don't find it.

Brian said:
Ted said:
can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which continues
past this cycle.", vbCritical, "Critical")
End If
End Sub

It would help if you indicated in what way it isn't working. Do you get an
error message, and if so, what? Or, if the events don't fire at all, make
sure that "Confirm Record Changes" is ticked in Options, and that the events
in the form's property sheet are set to "[Event Procedure]"
 
thanks ozzone, i found it and it checks out ok.

ted

Ozzone said:
From the Access window, not the VBA editor, Tools > Options... > Find/Edit tab

Ozzone


Ted said:
brian,dirk:

i'm having trouble locating where the special text you're implicating is
located. i looked under all four tabs of options under tools in the vba and
don't find it.

Brian said:
can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which
continues
past this cycle.", vbCritical, "Critical")
End If
End Sub

It would help if you indicated in what way it isn't working. Do you get an
error message, and if so, what? Or, if the events don't fire at all, make
sure that "Confirm Record Changes" is ticked in Options, and that the events
in the form's property sheet are set to "[Event Procedure]"
 
In that case, have you set breakpoints in your events? By doing this you can
interrupt the code thats executing and follow it step by step to see whats
happening.
To do this, go in each event that you want to trace and right-click the line
where you want the program to break, but not on a Dim statement. Select
Toggle, Breakpoint. You can also set the current line using the Debug menu
item.

Then go back into your form and perform the actions where you are having
problems, in your case, go delete an indivisual/PK .

IF the program breaks to the event, you know the event fired. Now you add
watches to see the values of your fields/variables and step through the code
using F8 or the Debug menu item. Add a watch by right-clicking a
field/variable name and select Add Watch. If you dont see the Watch Window
in the VBA editor, enable it with the View menu item.

If you find out the events are firing, then refer back to Dirk's post and
read his last two points again. I imagine you'll find that is where your
problem lies.

Ozzone


Ted said:
thanks ozzone, i found it and it checks out ok.

ted

Ozzone said:
From the Access window, not the VBA editor, Tools > Options... > Find/Edit tab

Ozzone


Ted said:
brian,dirk:

i'm having trouble locating where the special text you're implicating is
located. i looked under all four tabs of options under tools in the vba and
don't find it.

:

can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which
continues
past this cycle.", vbCritical, "Critical")
End If
End Sub

It would help if you indicated in what way it isn't working. Do you get an
error message, and if so, what? Or, if the events don't fire at all, make
sure that "Confirm Record Changes" is ticked in Options, and that the events
in the form's property sheet are set to "[Event Procedure]"
 
hi ozzone,

this is really a great great tutorial on how to debug a stalled program. i
really appreciate it :-)

my problem may be that the events i'm queuing up with the code have not the
ability to use the 'Contueing' value because of something Dirk Goldgar said
having to do with a fact that the record's already been deleted by the time
these events are actuated and the variable's being inacessible.

he's suggested i create a module level variable in some vba on the Delete
event ; this is giving me pause to think since there's a function (i
borrowed) there already and when i tried to create a Public variable
(something like "Public Msg1 as Integer" or other), it gave me a message
about not allowing this for some reason.

here's the code in On Delete in case it looks like you can figure out how to
get past the error message monster :-)
Public Function acbLogDelete( _
strTableName As String, varPK As Variant) As Integer

' Record deletion of a record in the
' log table

On Error GoTo HandleErr

acbLogDelete = acbLog(strTableName, varPK, mconLogDelete)

ExitHere:
Exit Function

HandleErr:
MsgBox "Error " & Err.Number & ": " & Err.description, _
, "acbLogDelete()"
Resume ExitHere
End Function

the other thing i'm contemplating is dropping a delete button on the
sub-form and using the OnClick event to trigger the msgBox response(s) if
this doesn't work out.

with best regards,

-ted

Ozzone said:
In that case, have you set breakpoints in your events? By doing this you can
interrupt the code thats executing and follow it step by step to see whats
happening.
To do this, go in each event that you want to trace and right-click the line
where you want the program to break, but not on a Dim statement. Select
Toggle, Breakpoint. You can also set the current line using the Debug menu
item.

Then go back into your form and perform the actions where you are having
problems, in your case, go delete an indivisual/PK .

IF the program breaks to the event, you know the event fired. Now you add
watches to see the values of your fields/variables and step through the code
using F8 or the Debug menu item. Add a watch by right-clicking a
field/variable name and select Add Watch. If you dont see the Watch Window
in the VBA editor, enable it with the View menu item.

If you find out the events are firing, then refer back to Dirk's post and
read his last two points again. I imagine you'll find that is where your
problem lies.

Ozzone


Ted said:
thanks ozzone, i found it and it checks out ok.

ted

Ozzone said:
From the Access window, not the VBA editor, Tools > Options... > Find/Edit tab

Ozzone


:

brian,dirk:

i'm having trouble locating where the special text you're implicating is
located. i looked under all four tabs of options under tools in the vba and
don't find it.

:

can anyone tell me why this code's not working in my a2k mdb:

Private Sub Form_AfterDelConfirm(Status As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you have just deleted an AE which continues past
this cycle.", vbCritical, "Critical")
End If
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.[Continuing].Value = "Yes" Then
Msg1 = MsgBox("Be advised you are preparing to delete an AE which
continues
past this cycle.", vbCritical, "Critical")
End If
End Sub

It would help if you indicated in what way it isn't working. Do you get an
error message, and if so, what? Or, if the events don't fire at all, make
sure that "Confirm Record Changes" is ticked in Options, and that the events
in the form's property sheet are set to "[Event Procedure]"
 
Ted said:
dirk, how would i grab the value of the Continuing variable in the
delete event (i pasted it in my posting to Ozzone)? i am relative
newbie.

You'd have to declare a variable at module level in the form; that is,
outside of any procedure. For example, you might do something like
this:

'----- start of code for form's module -----
Option Compare Database
Option Explicit

Dim mblnContinuing As Boolean

Private Sub Form_Delete()

' Save flag indicating whether record being deleted is
' continuing or not.
mblnContinuing = (Me.[Continuing].Value = "Yes" )

'** Note: I'm taking your word for it that the field
' [Continuing] is a text field that will have a value
' equal to the string "Yes". It may be that this is
' really a boolean (Yes/No) field, in which case its
' value will not actually be a string at all, but rather
' will be equal to one of the constants {True, False}.

End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)

If Status = acDeleteOK _
And mblnContinuing Then
MsgBox _
"Be advised you have just deleted an AE which " & _
"continues past this cycle.", _
vbCritical, _
"Critical"
End If

End Sub


Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As
Integer)

If mblnContinuing Then
MsgBox _
"Be advised you are preparing to delete an AE " & _
"which continues past this cycle.", _
vbCritical, _
"Critical"
End If

End Sub

' ... there may be other code in the form's module ...

'----- end of code for form's module -----
 
No problem, and thanks. It just so happens im stumped with my own problem
using the same events. Mine is a timing issue i believe, still working on it.

Let us know if Dirk's solution solves your problem. Perhaps if Dirk has a
moment he can browse my post "Repost - Nearly got it..." :)

Ozzone
 
Back
Top