One thing that jumps out at me is that you're setting the strlabelVal
variable to be the caption of the first option button/checkbox in the option
group, but you never reset it to the caption of the label for the second,
third, or fourth option button/checkbox? (If I am understanding that you
want this to change, that is.) So, in your last code block, you will always
see the same label caption -- namely, the first item's.
--
Ken Snell
<MS ACCESS MVP>
Pedro said:
I have a form that is not bound to a table. it basically a check list. The
users need to choose one of 4 options for each item on the list. The option
group label contains the list item name. I need to retrieve this to enter it
into a table field along with the option they have chosen. There is a submit
button so that once they have entered the choices for each list item I am
then using a recordset to do the insert into the table. So I loop through
each option group extracting the label caption (list item) and the option
group value (choice for that specific list item). The problem occurs
(inconsistently) when the label capyion changes from item(0) to item(4) and
vice versa? This gives me a data type mismatch error. Here is my code:
Private Sub cmdSubmit_Click()
Dim lblCaption As Label
Dim objOptGrp As OptionGroup
Dim strlabelVal As String
Dim chkOne, chkTwo, chkThree, chkFour As CheckBox
Dim rsTicklist As Recordset
Dim dbsLHSS As Database
Dim ctl As Control
'Set dbsLHSS = CurrentDb
'Set rsTicklist = dbsLHSS.OpenRecordset("tbl_tickList", dbOpenDynaset, dbAppendOnly)
For Each ctl In Me.Controls
If (ctl.ControlType = acOptionGroup) Then
Set objOptGrp = ctl
Set lblCaption = objOptGrp.Controls.Item(0)
strlabelVal = lblCaption.Caption
Debug.Print strlabelVal
Set chkOne = objOptGrp.Controls.Item(1)
Debug.Print "check 1 " & chkOne.Name '***Just me trying to find
out which list items are causing trouble.
Set chkTwo = objOptGrp.Controls.Item(2)
Debug.Print "CHECK 2 " & chkTwo.Name
Set chkThree = objOptGrp.Controls.Item(3)
Debug.Print "CHECK 3 " & chkThree.Name
Set chkFour = objOptGrp.Controls.Item(4)
Debug.Print "CHECK 4 " & chkFour.Name
'With rsTicklist
'.AddNew
'!School = strSchoolName
'!Theme = strlabelVal
'!DateOfAssessment = dtAssessDate
Select Case objOptGrp.Value
Case Is = 1
'!GoodUpToDate = True
MsgBox strlabelVal & " 1st" *****This is just so I can
check the correct options are being submitted