Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving a checkbox in VB database.

Status
Not open for further replies.

1x2z3

Programmer
Sep 18, 2003
39
ZA

1. I have a Checkbox control as above in my VB application.
2. I created a Boolean in Access for the Checkbox value.
3. When the Checkbox is checked the current Date & Time is entered automatically.
4. When I save it, Date & Time is save but the Checkbox isn’t


Here is the coding I used :
______________________________________________________
General Declaration

Dim cn As ADODB.Connection 'Connect to a Database.
Public rs As ADODB.Recordset 'Set records.
_______________________________________________________

Private Sub cmdSave_Click()

rs!chkCharged = chkCharged.Value & ""
________________________________________________________

Public Sub PopulateControls()

chkCharged.Value = rs!chkCharged & ""
_________________________________________________________

Private Sub chkCharged_Click()

If chkCharged.Value = Checked Then
txtCharged.Text = Date
txtCTime.Text = Time
txtCharged = Format(Date, "yyyy-mm-dd")
ElseIf chkCharged.Value = Unchecked Then
txtCharged.Text = ""
txtCTime.Text = ""
End If

End Sub
 

You are going to have to check the value of the check box and set the field appropriately on the save ...
[tt]
If chkCharged.Value = vbChecked Then
rs!chkCharged = True
Else
rs!chkCharged = False
End If
[/tt]
and visa-versa on the view of the record.
[/tt]
If rs!chkCharged = True Then
chkCharged.Value = vbChecked
Else
chkCharged.Value = vbUnchecked
End If
[/tt]

BTW, have you read FAQ222-2244 item 15 yet?

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top