Help with Optionbutton

S

SF

I had a questionaire form that consist of 6 several optionbutions. On my
form, I put these 6 option buttons as below by hope to replace their label
(option1, option2...) to a set of meaningful text from a recordset based on
Qt_QuestionTypeID (1 for Yes/No, 2 for TextBox, 3 for OptionButton)


() Option1
() Option2
() option3
() Option4
() Option5
() option6


I put a code in my form On Current Event as below

Const NUMOPTIONS = 6

Dim I As Integer
Dim s As String
Dim db As DAO.Database
Dim ds As DAO.Recordset

Me.focus.SetFocus

Select Case Me![Qt_QuestionTypeID]

' Multiple
Case 1:
Me![Re_Response_e].Visible = False
Me![Re_Number].Visible = True
Me![Re_YesNo].Visible = False
Me![Re_OLE].Visible = False
Me!Table.Visible = False
' Create a recordset to hold the captions for each question.

Set db = CurrentDb()
Set ds = db.OpenRecordset("Select * from typSurveyQuestionMultiple
where Qm_QuestionID = " & Me![Re_QuestionID] & ";")

If ds.RecordCount > 0 Then
ds.MoveLast
ds.MoveFirst

For I = 1 To NUMOPTIONS
If (Not ds.EOF) Then
If Not IsNull(ds![Qm_OptionText]) Then

Me("Option" & I).Caption = ds![Qm_OptionText]
Me("Option" & I).Visible = True
Me("OptionButton" & I).Visible = True
End If
ds.MoveNext
Else
Me("OptionButton" & I).Visible = False
Me("Option" & I).Visible = False
End If

Next I
ds.Close
End If


Case 2
case 3
case 4
end select

I got 'Item not found in this collection'


Could someone advice?

SF
 
S

SF

I did not the field name corrctly.
If Not IsNull(ds![Qm_OptionText]) Then >> If Not
IsNull(ds![Qm_OptionText_e]) Then

Problem solve now. Thank you

SF
Douglas J Steele said:
What line of code is it complaining about?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SF said:
I had a questionaire form that consist of 6 several optionbutions. On my
form, I put these 6 option buttons as below by hope to replace their
label
(option1, option2...) to a set of meaningful text from a recordset based on
Qt_QuestionTypeID (1 for Yes/No, 2 for TextBox, 3 for OptionButton)


() Option1
() Option2
() option3
() Option4
() Option5
() option6


I put a code in my form On Current Event as below

Const NUMOPTIONS = 6

Dim I As Integer
Dim s As String
Dim db As DAO.Database
Dim ds As DAO.Recordset

Me.focus.SetFocus

Select Case Me![Qt_QuestionTypeID]

' Multiple
Case 1:
Me![Re_Response_e].Visible = False
Me![Re_Number].Visible = True
Me![Re_YesNo].Visible = False
Me![Re_OLE].Visible = False
Me!Table.Visible = False
' Create a recordset to hold the captions for each question.

Set db = CurrentDb()
Set ds = db.OpenRecordset("Select * from typSurveyQuestionMultiple
where Qm_QuestionID = " & Me![Re_QuestionID] & ";")

If ds.RecordCount > 0 Then
ds.MoveLast
ds.MoveFirst

For I = 1 To NUMOPTIONS
If (Not ds.EOF) Then
If Not IsNull(ds![Qm_OptionText]) Then

Me("Option" & I).Caption = ds![Qm_OptionText]
Me("Option" & I).Visible = True
Me("OptionButton" & I).Visible = True
End If
ds.MoveNext
Else
Me("OptionButton" & I).Visible = False
Me("Option" & I).Visible = False
End If

Next I
ds.Close
End If


Case 2
case 3
case 4
end select

I got 'Item not found in this collection'


Could someone advice?

SF
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top