Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

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

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

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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.
    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simulate clicking a button in VBA code (Access

    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

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Simulate clicking a button in VBA code (Access

    See for example WithEvents and RaiseEvent.

Posting Permissions

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