Actually I'm doing something very similar, but when you
delete a record, something has to tell the indicator to
refresh itself so that it notices the change in
[SubformName].[Form].[Recordset].[RecordCount] or
whatever. There can be up to one child record per
subform, so I'm checking the child record ID as opposed to
the record count.
Perhaps some code will better illustrate the scenario:
I have been running this small code fragment in the Main
form's *Current* event:
With Me
!lblGIS.BackColor = fnIndicatorColor
(.GISsubform.Form.GIS_PRJ_ID)
!lblAdmin.BackColor = fnIndicatorColor
(.AdminSubform.Form.ADM_PRJ_ID)
!lblGPS.BackColor = fnIndicatorColor
(.GPSsubform.Form.GPS_PRJ_ID)
!lblTOPO.BackColor = fnIndicatorColor
(.TOPOsubform.Form.TOP_PRJ_ID)
!lblCADD.BackColor = fnIndicatorColor
(.CADDsubform.Form.CAD_PRJ_ID)
!lblROW.BackColor = fnIndicatorColor
(.ROWsubform.Form.ROW_PRJ_ID)
End With
Here's the *fnIndicatorColor* function code:
Public Function fnIndicatorColor(varChildID As Variant) As
Long
If Not IsNull(varChildID) Then
fnIndicatorColor = 65280 'Green
Else
fnIndicatorColor = 0 'Black
End If
The above code works fine, except when a child record is
deleted, I have no reliable trigger to requery the
indicators *after* the deletion.
The best I have been able to do is "Me.Parent.Requery" in
the subforms' *AfterInsert* events to detect additions.
Obviously, I'm missing something if I can't detect a
simple record deletion. I suppose I could use the timer
event, but I hate to do so.
As another kindof hokey resort, I'm also considering
adding an invisible record ID textbox control on each of
the subforms. I believe I can make the indicators refresh
in real time if the value in these controls changes to
null or not null. I'd rather not, but I'm running out of
ideas.
-----Original Message-----
I have an AXP form with a set of indicators that show, at
a quick glance, which subforms contain records. These
indicators get refreshed each time the user navigates from
one parent record to the next or whenever a new child
record is added.
The indicators also need to be refreshed whenever a child
record is *deleted*, but AXP has no "AfterDelete" event.
I've tried using the "On Delete" event, but this event is
raised *before* the record is physically deleted, so my
indicators continue to see the child record and remain
unchanged.
I would like to define my own "AfterDelete" event, but I'm
having difficulty defining a generic method for detecting
a record deletion. Does anyone have any ideas?
Though Allen Browne has answered your question by suggesting the
AfterDelConfirm event (and you can use the Delete event to count the number
of records being confirmed), I wonder if you really need to do this at all.
What's wrong with putting a text box on your main form with a controlsource
like this:
=[SubformName].[Form].[Recordset].[RecordCount]
(where "SubformName" is the name of the subform control on the main form).
In my tests, it keeps track of the number of records on the subform without
any code. I haven't used it extensively in practice, but it seems worth
pursuing.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup, not by e-mail)
.