Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2004
    Posts
    52

    Red face Unanswered: Source object that triggers event

    I have a combo, with an event 'On change' associated in VBA.

    It looks like this:

    private sub combo1_change()
    ...code...
    end sub

    I want to reference the object that triggers this event (combo1). How should I do this?

    Normally I would think by changing the sub to

    private sub combo1_change(source as control)

    But this gives the error that the event procedure does not match description.

    Any suggestions?

    Thanks a lot

  2. #2
    Join Date
    Feb 2004
    Posts
    199
    private sub combo1_change(source as control)
    won't work, of course.
    why do you need this?
    you can't refer to the combo1 directly?
    MDB, ADP <-> MS SQL + VBA, ADO & RDO, .NET, Oracle, Java/Jsp.

  3. #3
    Join Date
    Mar 2004
    Posts
    52
    I have an array of objects called 'question', which contains a reference to a combo box. On 'form load', I map each combo reference with a combo on my form.

    Now, when an event triggers (a combo gets changed on the screen), I want to link this do one of the 'question' objects from the array. (I will run though the array and compare the source reference of the event with the references in my array).

  4. #4
    Join Date
    Feb 2004
    Posts
    199
    array of objects is possible in VB , not in MS Access VBA, are you working in VB? if yes, then in VB event handler recives an index of source object that fired an event.
    private sub combo1_change(Index as integer)
    MDB, ADP <-> MS SQL + VBA, ADO & RDO, .NET, Oracle, Java/Jsp.

  5. #5
    Join Date
    Feb 2004
    Posts
    199
    in Access VBA there is only one way to create Objects Array - create/load them at runtime , but in this case they won't have an INdex and you won't be able to figure out event source object .
    try use object's tag or some other tricks
    MDB, ADP <-> MS SQL + VBA, ADO & RDO, .NET, Oracle, Java/Jsp.

  6. #6
    Join Date
    Mar 2004
    Posts
    52
    I'm working in A97 VBA.

    It IS possible to have an array of objects in VBA (dim questions(100) as clquestion).

    I think you might be mistaking with 'control arrays', which indeed you only have in VB.

    But still, my problem remains...

  7. #7
    Join Date
    Feb 2004
    Posts
    199
    dim questions(100) as clquestion

    is the clquestion a combobox object , put on your form, where you use this code?

    strange, this sintax doesn't work in Access2k/2002/2003.
    maybe I missed someting , but anyway, I think tag is way out
    and you may need to use WithEvents statement
    MDB, ADP <-> MS SQL + VBA, ADO & RDO, .NET, Oracle, Java/Jsp.

  8. #8
    Join Date
    Mar 2004
    Posts
    52
    The question object is an object that HAS a combobox (besides some other fields).

    I will look into the tag field and the withevents. Thanks for your help!

  9. #9
    Join Date
    Feb 2004
    Posts
    199
    interesting situation, never have thought about it

    1) to catch dinamic object event , you need withevets statement
    if clquestion is object name (not instance name that is put on a form),
    you should use sintax:
    dim withevents questions as clquestion
    2) but you have array
    dim withevents questions(100) as clquestion
    won't work in Access VBA
    so as I gues there is no way to catch objects array events in Access
    MDB, ADP <-> MS SQL + VBA, ADO & RDO, .NET, Oracle, Java/Jsp.

  10. #10
    Join Date
    Feb 2004
    Posts
    199
    I mean that you can use this code
    ====
    dim questions(100) as clquestion
    ...

    private sub questions_change()
    ...
    end sub

    ====

    but the questions_change never will be called becose it isn't declared as event source.
    MDB, ADP <-> MS SQL + VBA, ADO & RDO, .NET, Oracle, Java/Jsp.

Posting Permissions

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