Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / January 2005

Tip: Looking for answers? Try searching our database.

Using Eval to call a control event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carl Rapson - 27 Jan 2005 20:48 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.