Identifying selected subform records

  • Thread starter Thread starter Kent
  • Start date Start date
K

Kent

I have a subform in datasheet view. If a user wants to
delete records in the subform, they can highlight those
records via the recordselectors and press delete. I need
to identify those records and retrieve data from those
selected subform records before they are deleted. I know
to perform my test within the Form_BeforeDelConfirm event
of the subform before the records are actually deleted.
But, the ItemsSelected property seems to apply only to
controls, not forms or subforms, so I can't perform
my "For Each ... " statement.

I feel like I'm making this too hard or it's so obvious I
can't see the solution.

How do I identify the selected records in the subform
before they are deleted?
 
Kent said:
I have a subform in datasheet view. If a user wants to
delete records in the subform, they can highlight those
records via the recordselectors and press delete. I need
to identify those records and retrieve data from those
selected subform records before they are deleted. I know
to perform my test within the Form_BeforeDelConfirm event
of the subform before the records are actually deleted.
But, the ItemsSelected property seems to apply only to
controls, not forms or subforms, so I can't perform
my "For Each ... " statement.

I feel like I'm making this too hard or it's so obvious I
can't see the solution.

How do I identify the selected records in the subform
before they are deleted?

The Delete event fires for each record being deleted, before the
BeforeDelConfirm event (which only fires once). In the Delete event,
you can capture information from the record being deleted.
 
Dirk,

I'm finding that your suggestion ... at least the way I
understand it ... isn't working. I put a msgbox in the
Delete event of the subform. I ran the main form then
highlighted 3 records in the subform and pressed the
delete key. I got a system message telling me that I will
be deleting 3 records. I selected OK and the records are
gone. I did not see the 3 message boxes appear, one for
each record that was being deleted, which I was expecting
to see.

Am I doing something incorrectly? I'm using Access 2000
in an XP environment.
 
Hang on ... It worked this time. I made changes to the
Delete event, but the [Event Procedure] text was on listed
in the event property list. Once I forced that into the
Delete Event property list, it worked. That doesn't
really give me a very comfortable feeling ... but it did
work.

Thank you for your help.
 
Kent said:
Dirk,

I'm finding that your suggestion ... at least the way I
understand it ... isn't working. I put a msgbox in the
Delete event of the subform. I ran the main form then
highlighted 3 records in the subform and pressed the
delete key. I got a system message telling me that I will
be deleting 3 records. I selected OK and the records are
gone. I did not see the 3 message boxes appear, one for
each record that was being deleted, which I was expecting
to see.

Am I doing something incorrectly? I'm using Access 2000
in an XP environment.

It works fine for me, so I think you must have done something wrong.
Try this simple test. Open the subform in design view. Open the
property sheet for the form. Click on the Event tab. On the "On
Delete" line, enter this:

=MsgBox("Delete event")

Now save and close the subform.

Open the main form in form view. Select one or more records on the
subform. Click the Delete Record toolbar button or press the Delete
key. You *should* see the "Delete event" message box once for each
record you had selected -- I do. Then you can expect to see the Delete
Confirmation prompt, asking you if you really want to delete all those
records.

Let me know if this really doesn't work for you.
 
Kent said:
Hang on ... It worked this time. I made changes to the
Delete event, but the [Event Procedure] text was on listed
in the event property list. Once I forced that into the
Delete Event property list, it worked. That doesn't
really give me a very comfortable feeling ... but it did
work.

Thank you for your help.

You're welcome. But why should it give you an uncomfortable feeling?
You can write all the event procedures you want, but unless the event
property is set to tell Access to call those event procedures when
events are raised, you can't expect anything to happen.

Now, normally Access will set the event property if you are in the code
module and type in -- or paste in -- a properly defined procedure header
for one of the available events. Usually it's pretty good at this, but
there are things you can do that will confuse it. I don't know what
happened in this case, but I'm glad to see that you discovered the
problem.

Good luck!
 
Back
Top