CreateEventProc not firing

C

Chad Kuester

Code successfully created with CreateEventProc is not bound to the control.

Hello! I installed Office 2003 SP3. I know MS is aware of the checkbox bug
in Office 2003 SP3. Meanwhile I thought I'd write a routine to try and patch
any forms I have with checkboxes. I've noticed a condition that I think may
be an open issue.

What does work:

I created a blank form with a single checkbox called Check3. I go to the
VBA editor and manually type in

Public Sub Check3_Click()
msgbox "hi"
end sub

now when I go back to the form and right-click properties, it shows an event
is linked. When I double click it takes me to the VBA editor and that sub.
Note: I did not link the code to the control via the control first - I went
straight to the code first. This is good.

What does not work:

When I create Check3_Click using CreateEventProc, the code correctly gets
added to my VBA form, but when I go right-click properties on the control, it
does not show an event handler! If I go to immediate mode and ask
debug.print check3.properties("OnClick")="" it answers True that it is blank!
In addition, at this time when I click on the control, the event does not
fire. Only until I bind the control and the VBA code together so properties
shows an event-handler does the code fire.

Here's the code I used: I obtained parts of it from the help file on
CreateEventProc.

-Chad


---------- Sample code ----------

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
Dim str As String
Dim CurControl As Control
Dim result As Integer
Dim frm As Form, mdl As Module, lngReturn As Long
Dim EventName As String

If (Application.Build < 8166) Then
' This patch is only needed with Office 2003 SP3
Exit Sub
End If

For Each CurControl In Me.Controls
If (CurControl.ControlType = acCheckBox) Then
EventName = ""
If (CurControl.Properties("AfterUpdate") = "") Then
EventName = "AfterUpdate"
ElseIf (CurControl.Properties("OnClick") = "") Then
EventName = "Click"
End If

If (EventName = "") Then
result = MsgBox("Unable to auto-patch the checkbox called: "
& CurControl.name & _
vbCrLf & _
vbCrLf & "You may have trouble clicking on this
checkbox. If so, try clicking " & _
"Records/Refresh Records then try clicking the checkbox
again." _
, vbOKOnly, "Unable to auto-patch")
Else
Set mdl = Form.Module

On Error Resume Next
lngReturn = mdl.CreateEventProc(EventName, CurControl.name)
If (Err.Number <> 0) Then
' This can occur if you have the editor open when this
procedure runs.
Exit Sub
End If
On Error GoTo 0

mdl.InsertLines lngReturn + 1, vbTab & "MsgBox ""Way cool!"""
End If
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top