Hi. I'm having a slight problem with an Access database I'm writing and wonder if any of you could shed some light on it!
To make it easy for the user to enter data into the database, it displays a series of forms, and data entry is made through the option groups, checkboxes and text boxes on the forms. Once all of the information is entered onto a form, it is stored in a temporary module in arrays. For the option groups, I simply store the value of the option group. For checkboxes, I use bitwise manipulation to store a value corresponding to the boxes ticked.
I use a naming convention for controls, where the first 3 letters denote what the control is, e.g. 'cbx' = checkbox. Then there is a number, denoting the question number and finally, there is a letter (starting at 'a') for each control used for the question. For example, if I had question 2 as:
2. Which soft-drinks do you buy?
a. Coca Cola
b. Dr Pepper
c. Tango
since you may buy more than one type of drink, I would use checkboxes, which would be labelled cbx2a, cbx2b and cbx2c.
Below is an example of the code I use to store the value in the store module (ESS_Store)
1. For Each C in Me.Controls
2. If C.ControlType = acCheckbox Then
3. N = Asc(UCase(Mid(C.Name, 5, 1))) - 65
4. If C.Value = True Then
5. ESS_Store.SD2 = ESS_Store.SD2 Or Power(2, N)
6. Else
7. ESS_Store.SD2 = ESS_Store.SD2 Xor Power(2, N)
8. End If
9. End If
10. Next C
Line 3 converts the letter at the end of the control name into a number, so that a = 0, b = 1, c = 2, etc... and stores it in the variable, N.
Line 5 Or's the current value of SD2 (which is the variable that holds the value of the checkboxes) with 2^N, if the checkbox is ticked. (i.e., this line sets the bit corresponding to the checkbox).
Line 7 Xor's the current value of SD2 with 2^N to clear the bit if the checkbox is NOT ticked.
Now this code is WRONG! Because the code is looping for every control on the form, XOr'ing the value if the checkbox is not ticked is having exactly the same effect as Or'ing the value if the checkbox IS ticked.
What I want is so that if the checkboxes are ticked and the information is stored in the store module, and then from the next form the user clicks the Back button to reload this form, the values will still be in place, drawn down from the store module.
Please tell me there is an easier way to do this!
Gareth
PS. I just know you're all saying, "what the hell is he on about?". Sorry, I'm not particularly good at explaining problems, especially complicated ones like this one! [sig][/sig]
To make it easy for the user to enter data into the database, it displays a series of forms, and data entry is made through the option groups, checkboxes and text boxes on the forms. Once all of the information is entered onto a form, it is stored in a temporary module in arrays. For the option groups, I simply store the value of the option group. For checkboxes, I use bitwise manipulation to store a value corresponding to the boxes ticked.
I use a naming convention for controls, where the first 3 letters denote what the control is, e.g. 'cbx' = checkbox. Then there is a number, denoting the question number and finally, there is a letter (starting at 'a') for each control used for the question. For example, if I had question 2 as:
2. Which soft-drinks do you buy?
a. Coca Cola
b. Dr Pepper
c. Tango
since you may buy more than one type of drink, I would use checkboxes, which would be labelled cbx2a, cbx2b and cbx2c.
Below is an example of the code I use to store the value in the store module (ESS_Store)
1. For Each C in Me.Controls
2. If C.ControlType = acCheckbox Then
3. N = Asc(UCase(Mid(C.Name, 5, 1))) - 65
4. If C.Value = True Then
5. ESS_Store.SD2 = ESS_Store.SD2 Or Power(2, N)
6. Else
7. ESS_Store.SD2 = ESS_Store.SD2 Xor Power(2, N)
8. End If
9. End If
10. Next C
Line 3 converts the letter at the end of the control name into a number, so that a = 0, b = 1, c = 2, etc... and stores it in the variable, N.
Line 5 Or's the current value of SD2 (which is the variable that holds the value of the checkboxes) with 2^N, if the checkbox is ticked. (i.e., this line sets the bit corresponding to the checkbox).
Line 7 Xor's the current value of SD2 with 2^N to clear the bit if the checkbox is NOT ticked.
Now this code is WRONG! Because the code is looping for every control on the form, XOr'ing the value if the checkbox is not ticked is having exactly the same effect as Or'ing the value if the checkbox IS ticked.
What I want is so that if the checkboxes are ticked and the information is stored in the store module, and then from the next form the user clicks the Back button to reload this form, the values will still be in place, drawn down from the store module.
Please tell me there is an easier way to do this!
Gareth
PS. I just know you're all saying, "what the hell is he on about?". Sorry, I'm not particularly good at explaining problems, especially complicated ones like this one! [sig][/sig]