Solved

convert check box value to bit type in SQL DB

Posted on 2007-04-04
3
809 Views
Last Modified: 2013-12-25
How can I convert a check box value, which is True or False to 1 or 0 and save to SQL server data table, the field type is "bit ". Thanks
0
Comment
Question by:Skaugen
3 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 18851399
The standard way is to use an If statement.

How is the checkbox connected to your database?

Leon
0
 
LVL 7

Expert Comment

by:prosh0t
ID: 18851920
a bit type is essentially a 'bool'.  If you're using ADO and you have a recordset, just do something like this:

rs!SQLCheckedField = (MyCheckBox.Value = vbChecked)

We'll probably need more details about how you're working with your database, though.





0
 
LVL 16

Accepted Solution

by:
JohnBPrice earned 500 total points
ID: 18863588
I do this frequently, so I have a few routines I like to make it simple with these you do

rs!SQLCheckedField = IntToBool(MyCheckBox.Value)

or visa versa

MyCheckBox.Value = BoolToInt(rs!SQLCheckedField)


Public Function BoolToInt(bitfield As Variant) As Integer
    'return vbchecked or unchecked based on bitfield
    If IsNull(bitfield) Then
        BoolToInt = vbGrayed 'I use null to indicate neither checked nor unchecked, aka unknown
    ElseIf bitfield Then
        BoolToInt = vbchecked
    Else
        BoolToInt = vbUnchecked
    End If
End Function

Public Function IntToBool(checkfield As Integer) As Boolean
    If checkfield <> 0 Then
        IntToBool = True
    Else
        IntToBool = False
    End If
End Function
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now