views:

67

answers:

1

Is it possible to raise built-in MS Access form events programmatically? I have a feeling it isn't but thought I would check. (I am using Access 2003).

For instance, I want to do something like this within a private sub on the form:

RaiseEvent Delete(Cancel)

and have it trigger the Access.Form delete event -- i.e. without actually deleting a bound record.

Note my delete event is not handled by the form itself but by an external class, so I can't simply call Form_Delete(Cancel).

A: 

I can understand your confusion -- I didn't explain any of the bigger context. Sorry.

Basically, the situation is I have an 'index' i.e. 'continuous-forms' form which is bound to a read-only query. The query has to be read only because it involves an outer join. But, I want to be able to delete underlying records from this form.

So my first thought was to do the deletion outside the form recordset, eg. using a delete query. And I was hoping to hook the standard Delete/BeforeDelConfirm/AfterDelConfirm events around this manual deletion routine by raising these events myself. But alas, this is not possible.

If the form itself handled these events, I could simply call the handlers (Form_Delete, etc), but my project has custom classes that handle form delete and update events (validation, confirmation, logging, etc.) for all the forms. (@Smandoli, it's not well-documented, I just discovered it a few months ago and use it extensively now -- maybe you know about it already -- you can set up external classes to handle your form events. See for example here)

Long story short, I found a workaround I'm satisfied with. It involves making the 'index' form a subform of another form that is bound to a recordset that can be deleted from. So the deletion can be done in the outer form using the standard Access form events, based on the selection in the inner form.

@Knox, I disagree in principle that being able to raise 'built-in' events yourself is difficult to document and maintain. Plenty of other frameworks depend on it. In practice, I agree with you, since we all have to work within the limitations of our tools and 'best practices' that evolve around those limitations. The blessing and curse of Access is its tight binding between recordsets and forms...

Eric G
I'm confused. This is bog-standard Access design -- you put the DELETE command button in the continuous form's header or footer, and run the delete code from there followed by a Me.Requery. Nothing complicated here at all, and no need for it to be in a parent form.
David-W-Fenton
If by "run the delete code" you mean run a delete query or using DAO, i.e. outside the form recordset, that is what my first thought was, and I explained above why that can't work for me: because I want to hook in to the standard form events. Yet because the form recordset is read-only, I can't simply DoCmd.RunCommand acCmdDeleteRecord. I think my workaround is elegant as workarounds go and am happy to share it with anyone who wants it.
Eric G