[AccessD] Programmaticly fill control events

Patricio Galleguillos pgalleguillos at plus.cl
Fri Feb 21 09:20:01 CST 2003


Hi Threaders (generic...) and Group

This was a good clue (acDesign) for Generating the string [Event
Procedure]. If opened in form view it won't work
    
DoCmd.OpenForm strFormName, acDesign, , , , acHidden

----------------

Made a test form with 2 controls (text boxes) and everything goes OK
with the click (or OnClick) event but testing with beforeUpdate or
AfterUpdate gives error 438 - object does not accept this property or
method. Button for debugging disabled... any clues?

Saludos Cordiales,
Patricio Galleguillos



-----Mensaje original-----
De: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com] En nombre de Stuart Sanders
Enviado el: viernes, 21 de febrero de 2003 10:09
Para: accessd at databaseadvisors.com
Asunto: RE: [AccessD] Programmaticly fill control events

You could try something like this:

Function CreateNewControl()
    Dim frm As Form
    Dim lngLine As Long
    Dim strFormName As String
    Dim ctl As Control
    Dim strCtlName As String

    strFormName = "Form1"
    strCtlName = "cmdTest"
    DoCmd.OpenForm strFormName, acDesign, , , , acHidden

    Set frm = Forms(strFormName)
    Set ctl = CreateControl(strFormName, acCommandButton, acDetail,
vbNullString, _
        vbNullString, 1440, 720, 1440, 720)

    With ctl
        'set control properties
        .Name = strCtlName
    End With

    lngLine = frm.Module.CreateEventProc("Click", ctl.Name)
    With frm.Module
        .InsertLines lngLine + 1, _
            "' Purpose:      insert new event procedure test"
        .InsertLines lngLine + 2, _
            "On Error Resume Next"
        .InsertLines lngLine + 3, vbTab & _
            "msgbox ""Hello World"""

    End With

    DoCmd.Save acForm, strFormName
    DoCmd.Close acForm, strFormName
End Function

In order to test this, you will need a blank form called Form1.  Then
simply run the code.  It should open the form in design mode, add the
command button and on_click code, and then close the form again.  You
can open the form and test the button.

In your real app, it should be fairly simple to modify this (assuming
you know where the control should go) and then iterate through your
forms using any criteria to distinguish the correct forms.

Stuart


_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list