Hi all,
I have a checkbox in my program which returns 0/-1 to my database. When I read the database I want to show on the program whether the checkbox button is clicked or not. Please show me the code how to do that!
Printable View
Hi all,
I have a checkbox in my program which returns 0/-1 to my database. When I read the database I want to show on the program whether the checkbox button is clicked or not. Please show me the code how to do that!
I had a similar thing to do for school a while back, and I wrote these two functions:
This works inside Access, out of Access, replace CurrentDB with the handle to your database. This assumes an 'Options' table with PK/AutoNumber ID, char(100) Name, and Integer Value.Code:Public Function SetOption(sOptionName As String, iValue As Integer) As Boolean
Dim rst As Recordset
Dim bFound As Boolean
Set rst = CurrentDb.OpenRecordset("SELECT * FROM Options WHERE Name = """ & sOptionName & """")
If rst.RecordCount > 0 Then
rst.MoveFirst
rst.Edit
rst.Fields("Value").Value = iValue
bFound = True
rst.Update
Else
bFound = False
End If
rst.Close
SetOption = bFound
End Function
Public Function GetOption(sOptionName As String) As Integer
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * FROM Options WHERE Name = """ & sOptionName & """")
If rst.RecordCount > 0 Then
rst.MoveFirst
GetOption = rst.Fields("Value").Value
Else
GetOption = 0
End If
rst.Close
End Function
This assumes that you have it set up in the table. If you want me to send an example DB and program that would be easy.Code:Private Sub UpdateCheck()
chkMyCheckBox.Value = GetOption("chkMyCheckBox")
End Sub