Programming checkbox value!!! Fun & fruity challenge

MsLady

Traumatized by Access
Local time
Today, 06:41
Joined
Jun 14, 2004
Messages
438
I have five checkboxes on a form namely ck1, ck2, ck3, ck4, ck5.
A user can make more than one choice.
All the choices made should combine and go into one field into a table (ckboxes are not bound)

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

I want to have it so that when a user selects, for example: a combination of ck1, ck3 & ck5. My recordset reads: "mango, strawberry, guava".
when it selects ck2 & c1: "plum, mango". etc.

Now i have this part working and i am able to get correct fruit values into the table-field as text like "mango, strawberry, guava" if ck1, ck2, ck3 (combination) is selected.

Now, when a user goes back to update thier record from my form, I have no idea how to make sure the appropriate boxes are checked using the data in that field, so that they can update the check boxes. Since checkboxes only takes values of -1/0, yes/no, true/false, i run into problems on how to re-populate this checkboxes. say i have "mango, strawberry" in the field, i would like "ck1 & ck3) checked for the user to see and update.

What do you suggest? I need to have these fruity textvalues in my table-field, please help :o


This section to add ckboxes fruit values into my table:

Code:
Dim ckboxes5  as string

Public Function getCkboxes5Values()
Dim ckbox5a As String, ckbox5b As String, ckbox5c As String, ckbox5d As String, ckbox5e As String

If Form_frmSurvey.ck1 = True Then ckboxes5a = "mango"
    If Form_frmSurvey.ck2 = True Then ckboxes5b = "pear"
        If Form_frmSurvey.ck3 = True Then ckboxes5c = "strawberry"
            If Form_frmSurvey.ck4 = True Then ckboxes5d = "plum"
                If Form_frmSurvey.ck5 = True Then ckboxes5e = "guava"

ckboxes5 = ckboxes5a & "," & ckboxes5b & ", " & ckboxes5c & ", " & ckboxes5d & ", " & ckboxes5e
End Function

    rs.AddNew
    rs.Fields("Person") = vUser
    rs.Fields("Mnemonic") = vMnem
    rs.Fields("Question") = 5
    rs.Fields("Response") = ckboxes5

Load the values back up: How?
Code:
Private Sub loadValues()
On Error Resume Next
Dim sql As String, sql2 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)
    
    'sql2 = "
    
    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
        [color=red]'to be edited for checkboxes values
        'If ckboxes5 = "" Then
        'if value value in field contains "mango" :(
        ck1.Value = IIf(ckboxes5 = "*mango*", ck1.Value = True, ck1.Value = False)
        ck1.Value = rs(4)
        rs.MoveNext
        txtAnswer6.Value = rs(4)
        [/color]
    End If
    rs.Close

Any thoughts? Please help :)
 
Hi MsLady,

I recently took check boxes and Option boxes to write to table and then when opening form it reads the values from the tables. Check the link;

http://www.access-programmers.co.uk/forums/showthread.php?t=103048

As you can see I got a lot of help, oh well. But as you said Fun and Fruity challenge.:rolleyes:

I hope this helps, as you can see I used the Form_Open event.:p

Robert88
 
Last edited:
Wassup Robert,
Thanks for your reply.
LOL... you were practically talking to yourself in that thread! :eek:
I guess no hope for me on my fruity challenge either :D


ok...I'll check it out. Thanks
 
Hi MsLady,

You are right about talking to myself, but since I am doing so much learning I am pretty much pasting what I learn, in this case I eventually got to the solution, but always living in hope that someone will paste the solution like in Option_Group_Final.zip file at the end of the post, or should I say Option_Group_Final.mdb conatined within.

You have an interesting challenge, especially having more than one selected and all the different combinations you'll have to cover, my mind boggles on this one.

The post will only help you with taking values from form to table, table to form and also changing another forms default value after one closes, not sure if it will help?

Good Luck with it, still thinking on your multiply option check boxes..

Robert88
 
I would try and do something with the select case statement. Are you familar with it?
 
Robert,
I know what you mean about pasting as your learn. I have learned alot from here, specifically just searching and reading people's responses and solutions - and you can only do that if/when people post their answers for others to see also. So, thanks for doing that.

I studied your program, you are right. It's not particularly what i want.
What i am trying to accomplish is:

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 to remain checked (true) when i load my form.

Been stuck on this since yesterday...
I'll keep searching, hopefully some quality guru hears my cry for help :)
 
KeithG said:
I would try and do something with the select case statement. Are you familar with it?
Hi Keith, Yes, and i have tried that. That's doesn't help me in this case.
 

Users who are viewing this thread

Back
Top Bottom