Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Programming checkboxes!!! (2003)

    Hello friends,

    I have 5 ckboxes namely ck1, ck2, ck3, ck4, ck5
    Note: they are unbound. More than one choice can be made.

    The checkboxes represent like this:
    ck1 = "mango"
    ck2 = "pear"
    ck3 = "strawberry"
    ck4 = "plum"
    ck5 = "guava"

    If the value in my table field contains "guava" then ck5 is checked, for example, if the text in table says: "plum, guava, strawberry". I want ckboxes ck4, ck5, ck3 remain checked (true) when i load my form.

    How do i program this?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Programming checkboxes!!! (2003)

    Is your form bound to the table? If so, you can use code like this in the On Current event of the form:

    Private Sub Form_Current()
    Me.ck1 = (InStr(Me.FieldName, "mango") > 0)
    Me.ck2 = (InStr(Me.FieldName, "pear") > 0)
    Me.ck3 = (InStr(Me.FieldName, "strawberry") > 0)
    Me.ck4 = (InStr(Me.FieldName, "plum") > 0)
    Me.ck5 = (InStr(Me.FieldName, "guava") > 0)
    End Sub

    where FieldName is the name of the field containing the list of selected fruits.

    Note: the preferred way to store multiple-choice data is in a subtable with one record per item, not in one field with multiple data.

  3. #3
    New Lounger
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Programming checkboxes!!! (2003)

    Hi Hans, Thanks for ur quick reply <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    My form is not bound to the table. Thi is the procedure that load values on my form:

    <code>Private Sub loadValues()
    On Error Resume Next
    Dim sql As String, rs As DAO.Recordset

    sql = "select * from dbo_TS_Survey_Response where Person = """ & UserName() & """ and Mnemonic = """ & pMnem & """ Order By Question"
    Set rs = CurrentDb.OpenRecordset(sql, 2)

    If rs.RecordCount <> 0 Then
    rs.MoveFirst
    txtAnswer1.Value = rs(4)
    rs.MoveNext
    txtAnswer2.Value = rs(4)
    rs.MoveNext
    cboSelection3.Value = rs(4)
    rs.MoveNext
    txtAnswer4.Value = rs(4)
    rs.MoveNext

    'Question 5: load checkboxes
    'to be edited - how do i include here to check my boxes for values in the table?
    ck1.Value = rs(4)

    rs.MoveNext
    cboSelection6.Value = rs(4)
    rs.MoveNext
    txtAnswer7.Value = rs(4)
    rs.MoveNext
    txtAnswer8.Value = rs(4)
    cboMnemonic.Value = pMnem
    End If

    rs.Close

    End Sub
    </code>



    @Hans: Having the checkbox values on a different form is a good idea, but i am not sure how that works. I need to export the values of each user's answers to question into excel for analysis when im done (so i would need all the values the user selected for Question 5: to be ported into a field as e.g. "mange, plum, pear" if the user selects those 3 choices on the checkbox. This is what i am hoping to accomplish. what do you think is a better way?

    Thanks

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Programming checkboxes!!! (2003)

    You can replace the line

    ck1.Value = rs(4)

    with

    Me.ck1 = (InStr(rs(4), "mango") > 0)
    Me.ck2 = (InStr(rs(4), "pear") > 0)
    Me.ck3 = (InStr(rs(4), "strawberry") > 0)
    Me.ck4 = (InStr(rs(4), "plum") > 0)
    Me.ck5 = (InStr(rs(4), "guava") > 0)

    If you need the final result in the form of a concatenated string, you can leave the table structure as it is now.

  5. #5
    New Lounger
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Programming checkboxes!!! (2003)

    WOW!!!!! <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

    tHANKS SOOO MUCH!!! <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>
    I've been struggling with this since yesterday! You are the absolute best!
    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •