954,558 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Issues with check boxes

As far as I know when a check box is check the value should be 1 and when it is not checked it should be 0 correct?

In my case if I don't check the box its null and if I do its -1

Here is my code

Private Sub AddGeneral()
Dim rsAdd As Recordset
Dim sql As String

    If (chk1.checkstate = 1 And chk2.checkstate = 1) Then
        Kidney = "Both"
        MsgBox "Checked"
    ElseIf (chk1.Value = 1 And chk2.Value = "") Then
        Kidney = "Self"
    ElseIf (chk1.Value = "" And chk2.Value = 1) Then
        Kidney = "Family"
    Else
        Kidney = ""
    End If
    
    If (chk3.Value = 1 And chk4.Value = 1) Then
        Head = "Both"
    ElseIf (chk3.Value = 1 And chk4.Value = 0) Then
        Head = "Self"
    ElseIf (chk3.Value = 0 And chk4.Value = 1) Then
        Head = "Family"
    Else
        Head = ""
    End If

now i put -1 for the values and it worked but if i didnt check them some were 0 and some were null
if i have both check boxes checked it works
returns -1 for both
but if i just check one of the boxes it returns -1 and Null

ive tried -1 and Null, -1 and "", -1 and 0

Stewie
Light Poster
30 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

I can't really tell by your code, but is this VB express, .NET, or Legacy (VB 4, 5, or 6)? If it's Legacy VB, could you attach the project in a .zip to your next post, so that I can download your code, and see your problem. The truth is, I can't even replicate your error. I'm guessing, since vb6 doesn't have a .checkstate property for checkboxes, that it's not VB6. Something to check, and I see (based on your question) why you would have done this, but you are testing the checkboxes .value property against an empty string (""). Something to consider, would be testing against vbnull or vbnullstring.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

I was actually able to get the issue solved.
Thanks

Stewie
Light Poster
30 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

What was the solution? That way, should this problem arise again, we can have the fix available?

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You