I'm programmatically setting a combo box value using a DLookUp, and I would
like to simulate the combo box's AfterUpdate event. The problem is, I'm not
working with the control directly -- I'm iterating through the Controls
collection and setting each control, something like:
Dim ctl as Control
For Each ctl In Me.Controls
If (ctl.ControlType = acTextBox) Or (ctl.ControlType = acComboBox)
Then
ctl.Value = DLookup("[Default Name]", "[CSM Defaults]",
"[BA]='" & strBA & "' AND [Office]='" & strOffice & "'")
Eval ctl.Name & "_AfterUpdate()"
End If
End If
Next
The control value gets set OK, but I get an error 2425 on the Eval statement
(the database can't find the function name). I know the control events are
Subs, not Functions; is that the problem? Does Eval only work with
Functions? Is there another way to do what I want, using either Eval or
another method?
Thanks for any information,
Carl Rapson
Brendan Reynolds - 27 Jan 2005 21:09 GMT
If you change the scope of the event procedures from Private to Public, you
can do it with CallByName ...
Public Sub Combo0_AfterUpdate()
MsgBox "Combo0 AfterUpdate"
End Sub
Public Sub Combo2_AfterUpdate()
MsgBox "Combo2 AfterUpdate"
End Sub
Private Sub Command4_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acComboBox Then
CallByName Me, ctl.Name & "_AfterUpdate", VbMethod
End If
Next ctl
End Sub

Signature
Brendan Reynolds (MVP)
> I'm programmatically setting a combo box value using a DLookUp, and I
> would like to simulate the combo box's AfterUpdate event. The problem is,
[quoted text clipped - 21 lines]
>
> Carl Rapson
Carl Rapson - 28 Jan 2005 15:56 GMT
Thank very much, Brendan, it works like a charm. That's the first time I've
come across CallByName. It definitely goes in my reference file.
Carl Rapson
> If you change the scope of the event procedures from Private to Public,
> you can do it with CallByName ...
[quoted text clipped - 41 lines]
>>
>> Carl Rapson