Link to home
Start Free TrialLog in
Avatar of angel7170
angel7170Flag for United States of America

asked on

Save Multiple Checkbox values to MS Access table

Hello,

I have a windows form created using Visual Basic where there is a multiple checkboxes applied. I want to be able to select multiple values and save them in one column in the table. I would like the format saved as
checkboxvalue1;checkboxvalue3;checkboxvalue4 etc...
 How can I do that?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To avoid parsing you can use BITWISE logic to combine and separate multiple integer values in one field  
for example :

'this code will set the value in variable x from the checkbox selection
    Dim x As Integer
    x = x Or IIf(checkboxvalue1.Checked, 1, 0)
    x = x Or IIf(checkboxvalue2.Checked, 2, 0)
    x = x Or IIf(checkboxvalue3.Checked, 4, 0)
    .....
    x = x Or IIf(checkboxvalueN.Checked, 2^N, 0)
    MsgBox(x)  


' this part will restore checkbox values from value in x
checkboxvalue1.Checked= ( x And 1 = 1)
checkboxvalue2.Checked= ( x And 2 = 2)
checkboxvalue4.Checked= ( x And 4 = 4)

the values you can use are 2^n
for example
2^0=1
2^1=2
2^2=4
2^3=8
2^4=16
2^5=32
....