Using VB6
I am using checkbox and combobox in a Form.
When i click the check box, the combobox will enable, by default combobox will be disable.
Code.
Private Sub chkbox1_Click()
combobox1.enable = true
End Sub
Private Sub chkbox2_Click()
combobox2.enable = true
End Sub
Output Code is
If chkbox1.Value = 1 Then
sql2 = "Select * from table1 where value = '" & combobox1 & "' "
ElseIf chkbox2.Value = 1 Then
sql2 = "Select * from table1 where value = '" & combobox2 & "'"
Else
sql2 = "Select * from table1"
End If
The above code is working, but when i click the two checkbox, then two combobox are enabled, then i run the query it is showing the combobox1 value.
For example
I selected the value = 50 from combobox1 (checkbox1 clicked)
I selected the value = 100 from combobox2 (checkbox2 clicked)
when i run the output code, then output is display the value where value = 50, it is not showing value = 100 also.
It should show both values in the output code
How to solve this issue.
Need vb6 code help
What is happening is if both are checked the first case is true, since
chkcombin1.Value = 1So you need to check to make sure that the other box is unchecked.
Edit op comments
Since you have multiple checkboxes then I would suggest this:
this isn’t tested nor is it optimal but it should give you an idea
SO what that does is writes the no checkboxes checked part of your statement, then it prepares the where clause, using a function to generate the necessary parts, if the where clause is an empty string it writes what it should be for 1 where, then appends all of the necessary
andclauses. Finally it combines the statement together. If there is nothing in the where clause then you get theSelect * from table1