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

Recommended Answers

All 3 Replies

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.

I was actually able to get the issue solved.
Thanks

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.