How to determine which dynamically generated control was clicked

L

llowwelll

I have a worksheet that updates from a database query every fiv
minutes. With each update, a row is generated for each record in th
query. The number of records returned from the query varies with eac
new query. I have figured out (many, many thanks to Chip Pearson) ho
to dynamically generate a command button and its attached code for eac
record displayed on the worksheet.

However, now I need to figure out how to determine which command butto
was pressed when the user clicks on one of the command button
generated at runtime.

For example, the code that is generated for each command button look
like this:

Sub Button3_Click()

'Now I need to figure out, in this case, that button 3 (as oppose
to button 4 or 5) was pressed

End Sub

Any ideas or help would be very greatly appreciated!! Thank you i
advance
 
B

Bob Phillips

Surely, if it is the Button3 event, you must already know it is button 3?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
J

JE McGimpsey

Since the OP talked about "attached code" rather than "event", it could
be that the button is a Forms control with an attached macro...
 
B

Bob Phillips

Maybe, the _Click may have misled me.

Let's await the OP's response<G>.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

JE McGimpsey said:
Since the OP talked about "attached code" rather than "event", it could
be that the button is a Forms control with an attached macro...
3?
 
C

chris

Stick this in your attached Macro:

Sub MyMacro(
MsgBox Application.Calle
...
End Sub
----- llowwelll > wrote: ----

I have a worksheet that updates from a database query every fiv
minutes. With each update, a row is generated for each record in th
query. The number of records returned from the query varies with eac
new query. I have figured out (many, many thanks to Chip Pearson) ho
to dynamically generate a command button and its attached code for eac
record displayed on the worksheet

However, now I need to figure out how to determine which command butto
was pressed when the user clicks on one of the command button
generated at runtime.

For example, the code that is generated for each command button look
like this

Sub Button3_Click(

'Now I need to figure out, in this case, that button 3 (as oppose
to button 4 or 5) was presse

End Su

Any ideas or help would be very greatly appreciated!! Thank you i
advance
 
Top