Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2004
    Location
    Berlin, Germany
    Posts
    107

    Unanswered: trigger events by code

    hey guys,

    got a hopefully simple question but as it's friday ma brain's a bit sllooowwww.

    so .. how can i trigger the events of an object, say the change event of a combo, by code?

    the problem is that if u set a combo by code the change event is not triggered. k, i can easily do it by explicitely calling the event routine, but as i'm presetting cbos quite often i have a generic routine to do so - and it would be nice if it could handle the event trigger as well.

    best regards
    dirk

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Sadly no, you can't call intrinsic object events in the manner you're describing. However, you can create a generic function that accepts a combobox byRef which could be called from anywhere, passing in the effected combobox.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Mar 2004
    Location
    Berlin, Germany
    Posts
    107
    thanx teddy

    i was tryin sumtn alike. only how do i call the event routine .. as it is private to the forms module. so not accessible from sum generic code

    any idea?

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You have to approach it a little differently. Put the code that you want to be accessable in a public module. Then, in the comboboxes event, call the function you wrote in your public module. Your combobox now effectively calls a different function when its events are triggered.

    ie:

    Let's say you have a combo box that is supposed to display its current value in a message box in its afterupdate() event. You want to be able to trigger this same action from anywhere.

    First, create a new function in a module:
    Code:
    Public Function GenericAfterUpdateEvent(ByRef cboIn As ComboBox)
    MsgBox cboIn.Value
    End Function
    Now call your function from your combobox event:

    Code:
    Private Sub cboYourComboBox_AfterUpdate()
    GenericAfterUpdateEvent Me.cboYourComboBox
    End Sub
    Now say you want to trigger that same event from somewhere else:

    Code:
    Private Sub SomeOtherEvent()
    GenericAfterUpdateEvent forms!yourForm!cboYourComboBox
    End Sub
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Mar 2004
    Location
    Berlin, Germany
    Posts
    107
    k .. got the point. Didn't see that approach .. as i said it's friday. Yap, not the elegant solution that i's lookin for but very practicable.

    thanx a lot
    Dirk

    Quote Originally Posted by Teddy
    You have to approach it a little differently. Put the code that you want to be accessable in a public module. Then, in the comboboxes event, call the function you wrote in your public module. Your combobox now effectively calls a different function when its events are triggered.

    ie:

    Let's say you have a combo box that is supposed to display its current value in a message box in its afterupdate() event. You want to be able to trigger this same action from anywhere.

    First, create a new function in a module:
    Code:
    Public Function GenericAfterUpdateEvent(ByRef cboIn As ComboBox)
    MsgBox cboIn.Value
    End Function
    Now call your function from your combobox event:

    Code:
    Private Sub cboYourComboBox_AfterUpdate()
    GenericAfterUpdateEvent Me.cboYourComboBox
    End Sub
    Now say you want to trigger that same event from somewhere else:

    Code:
    Private Sub SomeOtherEvent()
    GenericAfterUpdateEvent forms!yourForm!cboYourComboBox
    End Sub

  6. #6
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    What I would suggest is an event function. If you have the cbo's name and the event you want to trigger then send it to a procedure that builds the event procedure's name and runs it.

    Code:
    Public Sub RunEvent(strControlName As String, _
                        strEventName As String)
                        
        Application.Run strControlName & "_" & strEventName
    
    End Sub
    I haven't tried it, but it might work for you.

  7. #7
    Join Date
    Mar 2004
    Location
    Berlin, Germany
    Posts
    107
    Thanx DCK,

    yap .. did try it - only hook is the event funcs are private . So run's not able to call them. Seems like there's no elegant solution for the prob.

    Anyway thanx for all the help!!
    Dirk

    Quote Originally Posted by DCKunkle
    What I would suggest is an event function. If you have the cbo's name and the event you want to trigger then send it to a procedure that builds the event procedure's name and runs it.
    Code:
    Public Sub RunEvent(strControlName As String, _
                        strEventName As String)                    
        Application.Run strControlName & "_" & strEventName
    End Sub
    I haven't tried it, but it might work for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •