• Simulate clicking a button in VBA code (Access 2003 / SP1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Simulate clicking a button in VBA code (Access 2003 / SP1)

    Author
    Topic
    #413991

    I need to simulate the act of clicking on a form’s button from within VBA code. In Access VBA Help I came upon the RaiseEvent statement and assumed that this is the way to do it. Following the instructions in that topic, I tried to raise the event cmdCancel_Click as follows:

    1. I declared the event at the module level of the class module of that form:
    Event cmdCancelClick()
    Note 1. Error Help says to omit the _ between cmdCancel and Click.
    Note 2. I don’t know if the declaration requires arguments.

    2. In code I insert the following statement:
    RaiseEvent cmdCancelClick
    Note 1. Using the de###### I can tell that the statement gets control.
    Note 2. Absolutely nothing happens. The system just continues to run.

    Is this the right way to simulate the user clicking on the cmdCancel button? If it is, please tell me what I’m doing wrong. If it is not, please tell me what I should be doing.

    Thank you, John Littell

    Viewing 3 reply threads
    Author
    Replies
    • #917162

      You don’t need to do all this. You can simply call the event procedure cmdCancel_Click to simulate clicking the button.

    • #917163

      You don’t need to do all this. You can simply call the event procedure cmdCancel_Click to simulate clicking the button.

    • #917230

      RaiseEvent is used to signal to any listening object that something has happened. It relies on event sinks declared WithEvents in some loaded class to monitor it and respond to the event. Hans’s suggestion is the appropriate way to handle this particular situation, not RaiseEvent, even though you could make it work with a bit of effort.

      • #917371

        Hans, Charlotte

        Hans, Thank you. Your suggestion worked perfrectly.

        Charlotte, Thank you also. After retiring from 40 years working with every type of computer made, I haven’t a clue understanding your explanation. I with I could. Can you point me to Help facilities?

        John Littell

      • #917372

        Hans, Charlotte

        Hans, Thank you. Your suggestion worked perfrectly.

        Charlotte, Thank you also. After retiring from 40 years working with every type of computer made, I haven’t a clue understanding your explanation. I with I could. Can you point me to Help facilities?

        John Littell

    • #917231

      RaiseEvent is used to signal to any listening object that something has happened. It relies on event sinks declared WithEvents in some loaded class to monitor it and respond to the event. Hans’s suggestion is the appropriate way to handle this particular situation, not RaiseEvent, even though you could make it work with a bit of effort.

    Viewing 3 reply threads
    Reply To: Simulate clicking a button in VBA code (Access 2003 / SP1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: