need to create generic code (1 Viewer)

N

nushk

Guest
Hi all ,
I would really appreciate if someone can help me .
I build an application that has more than 100 forms.
I want to generate code that creates event before del confirm to
all the forms in the database and adds the clause :
Response = AcDataErrContinue in all events.
I want to avoid the annoying l job of doing it separately to each form and I need generic code.Please help
Tx
Nushk
 

rockman

Senior Member
Local time
Today, 02:14
Joined
May 29, 2002
Messages
190
Create a Public Sub in a project module. Pass the form as an object to the Sub.

Example:
In a module-

Public Sub PerformTask(fForm as form)
....
End Sub

In each form-

Private Sub Form_BeforeUpdate
Call PerformTask(Me)
End Sub

HTH,
Jeff
 

Alexandre

Registered User.
Local time
Today, 16:14
Joined
Feb 22, 2001
Messages
794
This should put you on the right track. however, you would need to adapt it to check whether the event procedure already exists and act accordingly...

Code:
Option Compare Database
Option Explicit


Public Sub WriteToModules()
Dim mdl As Module
Dim strFormOpenCode As String
Dim objFrm As AccessObject, frm As Form


For Each objFrm In CurrentProject.AllForms
    'We've got to open the forms in Design view.
    'This will create a module for forms that don't have any
    DoCmd.OpenForm FormName:=objFrm.Name, View:=acDesign
    Set frm = Forms(objFrm.Name)
    Set mdl = Forms(objFrm.Name).Module

    
    'Set a reference to the event procedure
    frm.BeforeUpdate = "[Event Procedure]"

    
    'Write the code and save and close the form
    strFormOpenCode = vbCrLf & "Form_BeforeUpdate(Cancel As Integer)" _
    & vbCrLf & "YourCodeHere" & vbCrLf & "End Sub"
    With mdl
        .InsertText strFormOpenCode
    End With
    DoCmd.Close acForm, objFrm.Name, acSaveYes
Next objFrm


Set frm = Nothing
Set mdl = Nothing
Set objFrm = Nothing
End Sub
 

Users who are viewing this thread

Top Bottom