423,682 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,682 IT Pros & Developers. It's quick & easy.

Programmatically binding a checkbox to it's option group

P: n/a
Ok, so I'm creating a form on the fly. I can create the option group,
I can create the checkboxes, but I can't figure out how to bind them to
the option group I'm creating them within. I was hoping the fact that
creating them inside the option group would cause it to automatically
bind, but no go.
As it stands now I create the option group and bind it to a field in a
table, then create the checkboxes inside the option group. After that,
I try to reference it's option value property to assign it a value, but
since they aren't bound, the checkboxes don't have that property.
Here's my code:

Sub CreateFormControls()

Dim ctlLabel, ctlNew, ctlCheck, ctlCheck_2 As Control
Dim i, intOG_X, intOG_Y, intChk_X, intChk_Y, intLbl_X, intLbl_Y,
intCtlWidth, intCtlHeight As Integer
Dim frm As Form
Dim rst As Recordset
Dim strSQL As String

intOG_X = 1000: intOG_Y = 100
intChk_X = 1100: intChk_Y = 160
intLbl_X = 100: intLbl_Y = 100
intCtlWidth = 1500: intCtlHeight = 300

DoCmd.OpenForm "frmCustServMonEntry", acDesign

strSQL = "SELECT Max(dbo_tblCustServMonQues.QNUM) AS TotalQues FROM
dbo_tblCustServMonQues;"

Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset,
dbSeeChanges)

Set frm = [Forms]![frmCustServMonEntry]

i = 1
Do Until i > rst![TotalQues]

' Create option group control.
Set ctlNew = CreateControl("frmCustServMonEntry",
acOptionGroup, , "", "Q" & i, _
intOG_X, intOG_Y, intCtlWidth, intCtlHeight)
' Create first check box control.
Set ctlCheck = CreateControl("frmCustServMonEntry", acCheckBox,
, "Q" & i, "", _
intChk_X, intChk_Y, intCtlWidth - 1200, intCtlHeight - 100)
ctlCheck.OptionValue = -1
' Create second check box control.
Set ctlCheck = CreateControl("frmCustServMonEntry", acCheckBox,
, "Q" & i, "", _
intChk_X + 400, intChk_Y, intCtlWidth - 1200, intCtlHeight
- 100)
frm!ctlCheck.OptionValue = 0
' Create third check box control.
Set ctlCheck = CreateControl("frmCustServMonEntry", acCheckBox,
, "Q" & i, "", _
intChk_X + 800, intChk_Y, intCtlWidth - 1200, intCtlHeight
- 100)
frm!ctlCheck.OptionValue = 1
' Create fourth check box control.
Set ctlCheck = CreateControl("frmCustServMonEntry", acCheckBox,
, "", "", _
intChk_X + 1200, intChk_Y, intCtlWidth - 1200, intCtlHeight
- 100)
' Create child label control for option group.
Set ctlLabel = CreateControl("frmCustServMonEntry", acLabel, ,
ctlNew.Name, _
"Test", intLbl_X, intLbl_Y)

ctlNew.Name = "Q" & i
ctlLabel.Name = "lblQ" & i
intOG_Y = intOG_Y + 400
intLbl_Y = intLbl_Y + 400
intChk_Y = intChk_Y + 400

i = i + 1

Loop

DoCmd.OpenForm "frmcustServMonEntry", acNormal
DoCmd.Save acForm, "frmCustServMonEntry"
[Forms]![frmCustServMonEntry].SetFocus

End Sub

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Charles wrote:
Ok, so I'm creating a form on the fly. I can create the option group,
I can create the checkboxes, but I can't figure out how to bind them to
the option group I'm creating them within.


comboboxcontrol.Parent = optiongroupcontrol
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #2

P: n/a
Bas Cost Budde wrote:
Charles wrote:
Ok, so I'm creating a form on the fly. I can create the option group, I can create the checkboxes, but I can't figure out how to bind them to the option group I'm creating them within.


comboboxcontrol.Parent = optiongroupcontrol
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea


FYI, the problem seems to be that fact that I never changed the name of
the option group. When you use the createcontrol method you can
specify the parent of that control, which I was doing. However, since
I never changed the name of the optiongroup it didn't work.

So basically, it should look like this:

Set ctlNew = CreateControl("frmCustServMonEntry", acOptionGroup, , "",
"Q" & i, _
intOG_X, intOG_Y, intCtlWidth, intCtlHeight)
'name option group
ctlNew.Name = "Q" & i
' Create first check box control.
Set ctlCheck = CreateControl("frmCustServMonEntry", acCheckBox, , "Q" &
i, "", _
intChk_X, intChk_Y, intCtlWidth - 1200, intCtlHeight - 100)

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.