Programmatically Accessing the Event

  • Thread starter Thread starter ras
  • Start date Start date
R

ras

I need to edit the on click events for ALL of my command buttons in a large
access program. Is there any way to step thru each form and open the file
containing all the event procedures. Make changes and then save these
changes.
 
ras said:
I need to edit the on click events for ALL of my command buttons in a large
access program. Is there any way to step thru each form and open the file
containing all the event procedures. Make changes and then save these
changes.


Use this kind of procedure in your design utility module.

Public Sub FixClick()
Dim db As Database
Dim doc As Document
Dim frm As Form
Dim ctl As Control

Set db = CurrentDb()
For Each doc In db.Containers!Forms.Documents
DoCmd.OpenForm doc.Name, acDesign
Set frm = Forms(doc.Name)
For Each ctl In frm
If ctl.ControlType = acCommandButton Then
ctl.OnClick = "whatever"
End If
Next ctl
DoCmd.Close acForm, doc.Name, acSaveYes
Next doc

Mandatory Warning: Design changes should never be
done in a running application.
 
Back
Top