|
-
Feb 17th, 2013, 01:32 PM
#1
Thread Starter
Lively Member
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!
-
Feb 17th, 2013, 03:18 PM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 17th, 2013, 04:04 PM
#3
Thread Starter
Lively Member
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) :-(
-
Feb 18th, 2013, 03:44 AM
#4
Re: Dynamic Command Buttons- Single Macro
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 18th, 2013, 06:22 AM
#5
Thread Starter
Lively Member
Re: Dynamic Command Buttons- Single Macro
Great thank you, I will have a look through that!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|