VBA里动态生成的控件怎么取得相关控件的值呢,如OptionButton或CheckBox控件。
请教下大家,VBA里动态生成的控件怎么取得相关控件的值呢,如OptionButton或CheckBox控件,比如下面我自己写的一段代码,是OptionButton控件,但...
请教下大家,VBA里动态生成的控件怎么取得相关控件的值呢,如OptionButton或CheckBox控件,比如下面我自己写的一段代码,是OptionButton控件,但mybutton_Click事件触发后怎么知道我是选了哪个选项呢?(数据库链接代码省略)
Dim mycmd As Control
Dim WithEvents mybutton As CommandButton
Private Sub UserForm_Initialize()
strSQL = "select agent_name from initial1 group by agent_name"
rs.Open strSQL, cn, 1, 3
Dim c As Integer
c = 1
i = 0
While rs.EOF = False
Set mycmd = detail_form.Frame1.Controls.Add("Forms.OptionButton.1", "OptionButton" & c)
mycmd.Left = 10
mycmd.Top = 20 + i
mycmd.Width = 175
mycmd.Height = 20
mycmd.Caption = mycmd.Name
mycmd.Caption = Trim(rs(0))
i = i + 20
c = c + 1
rs.MoveNext
Wend
Set mybutton = detail_form.Frame1.Controls.Add("Forms.CommandButton.1", "CommandButton1")
mybutton.Left = 100
mybutton.Top = 220
mybutton.Width = 70
mybutton.Height = 20
mybutton.Caption = "确定"
i = i + 20
rs.Close
End Sub
Private Sub mybutton_Click()
MsgBox (livex002.ComboBox3.Value)
MsgBox (OptionButton1.Text) ’这里的OptionButton怎么取值呢?
End Sub 展开
Dim mycmd As Control
Dim WithEvents mybutton As CommandButton
Private Sub UserForm_Initialize()
strSQL = "select agent_name from initial1 group by agent_name"
rs.Open strSQL, cn, 1, 3
Dim c As Integer
c = 1
i = 0
While rs.EOF = False
Set mycmd = detail_form.Frame1.Controls.Add("Forms.OptionButton.1", "OptionButton" & c)
mycmd.Left = 10
mycmd.Top = 20 + i
mycmd.Width = 175
mycmd.Height = 20
mycmd.Caption = mycmd.Name
mycmd.Caption = Trim(rs(0))
i = i + 20
c = c + 1
rs.MoveNext
Wend
Set mybutton = detail_form.Frame1.Controls.Add("Forms.CommandButton.1", "CommandButton1")
mybutton.Left = 100
mybutton.Top = 220
mybutton.Width = 70
mybutton.Height = 20
mybutton.Caption = "确定"
i = i + 20
rs.Close
End Sub
Private Sub mybutton_Click()
MsgBox (livex002.ComboBox3.Value)
MsgBox (OptionButton1.Text) ’这里的OptionButton怎么取值呢?
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询