Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

convert check box value to bit type in SQL DB

Posted on 2007-04-04
3
Medium Priority
?
816 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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