[Help] Assign OnClick event to control through code. [Help]

BlueIshDan

☠
Local time
Today, 04:16
Joined
May 15, 2014
Messages
1,121
Hello, I have a lot of experience in the Visual Studio IDE environment and I have been working with Access VBA for almost a year now.

I am very used to generating my form controls in runtime and being able to create some cool user interface interactions by being able to say btnExample.OnClick += MyDynamicClickFunction

MyDynamicClickFunction(Object sender, EventArgs e).... code

Does anyone know of a way to assign functions to the events of already made controls on a form. Probably during the load event? :)

Now I have found that there are many ways to replicate Visual Studio's features by accessing User32 and replicating them, so it would also be great if anyone had a direction to point me towards.

Thanks!
BlueIshDan :)
 
I was able to reprogram the onclick of an existing button to an existing function like this:

Code:
btn2.OnClick = "=Runnit()"

where Runnit was a no-return value function in the same form:

Code:
Private Function Runnit()
MsgBox ("It ran.")
End Function

If you're looking to have more control over where the macros are or what's in the functions, have a look at Adezzi's reply in this thread:

http://bytes.com/topic/access/answe...namically-created-buttons-using-vba-ms-access
 
GREAT THANKS!

Now I'm going to step it up one haha.
Do you think you could figure out how to assign more than one function to the click event?
 

Users who are viewing this thread

Back
Top Bottom