Hi Travlos,
Is it possible that you may want to hide and unhide command
buttons based on the results of the query where you can dynamically
alter the captions, etc, or do you actually need to dynamically
create the buttons themselves?
If you still need to dynamically create the buttons, I do have
source code that uses the CreateControl function including a sample
to actually insert the _Click() source code for each button as you
create it. You can actually specify the source code in a string
variable and then call a private function inside the form, which
would be your "common code" for each of the Click events for each
command button. You would pass the name of the calling button
to that common private function.
If you're already using the CreateControl now, put your Click()
VBA code into a string variable (strCode, etc) and you can
do something like this:
Dim ctl As Control
Dim strCode As String
Set ctl = CreateControl(strGFormName, CONTROL_COMMAND_BUTTON, _
2, "", "", intLeft, intTop, intWidth, intHeight)
ctl.Name = "cmdButton1"
ctl.FontName = "MS Sans Serif"
ctl.FontSize = 8
ctl.FontWeight = FONTWEIGHT_BOLD
ctl.Caption = "Process A"
ctl.TabStop = True
strCode = ""
strCode = strCode & "Sub " & ctl.Name & "_Click ()" & vbCrLf
strCode = strCode & vbTab & Call CommonCode(" & ctl.Name & ")" & vbCrLf
strCode = strCode & "End Sub"
Forms(strFormName).Module.InsertText strCode
ctl.OnClick = "[Event Procedure]"
Some of the intrinsic constants (CONTROL_COMMAND_BUTTON, etc)
may be a little old, but this should give you a start on how
to add code dynamically when creating controls dynamically.
Hope that helps.
Warren
|