Dynamic Command Buttons- Single Macro
I have some code that loops through a series of rows, the data comes from a MySQL database and when a query button is clicked the code fires and a command button is created on each row.
The name of the command button is assigned by an ID field, which is a column from the database.
So far so good, this all functions correctly.
However, this is where I get stuck as I now have a series of buttons and depending on which button was clicked I need a different piece of code triggered.
I can't simply assign some code to each button, as these buttons get deleted and re-added depending on the data pulled back from the database.
So for example, on a query button click, a series of buttons with ID's 99, 101, 103 are created, then when the query button is clicked again, it deletes all rows and say pulls back ID's 88 and 113.
So, what I'm looking for is a piece of code that can tell which button was clicked, as I can't use the standard Private Sub btnsearch_Click() as the name of the buttons keeps changing.
I keep seeing code samples containing the following:
Application.Caller
However this does absolutely nothing, I suspect because it only works for buttons, not Command Buttons.
Help!
Re: Dynamic Command Buttons- Single Macro
you need to have a class for your buttons (controls) and add each dynamically created button to a class collection of buttons
there are examples in this forum, i remember posting in a thread that used these methods, search on calendar
Re: Dynamic Command Buttons- Single Macro
Hmm, I tried searching on calendar, there are 4 pages of hits, but I can't see one that seems to refer to this (well not obviously anyway) :-(
Re: Dynamic Command Buttons- Single Macro
Re: Dynamic Command Buttons- Single Macro
Great thank you, I will have a look through that!