Hi all, I know some of what I am doing is not the best possible solution but work with me. I have combobox that is populated from an access table. That works great. Now I have a checkbox that I use to update the checkbox field(Yes/No) in the same table based on the combobox selection. That too works great. My problem is I can't get the checkbox on the excel userform to reflect the correct status of the checkbox field based on the combobox selection. I can update with out problems, but can't always know what the status is. Can you help address this? The checkbox field value is in column 3 of the combobox if that helps.
Code:
Private Sub Classcbo()
Dim src As String
Dim i As Integer
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
'connect to the access database
Set cn = New ADODB.Connection
myConn = TARGET_DB
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open myConn
End With
Set rs = New ADODB.Recordset
src = "SELECT * FROM tblClasses "
rs.Open src, cn, adOpenDynamic, adLockBatchOptimistic
With Me.cboClasses
.Clear
.ColumnCount = 6
.Column = rs.GetRows
.ListIndex = -1
Font.Size = 12
End With
'End If
'Close ADO objects
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
Code:
Private Sub chkDisable_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim myConn As String
Dim src As String
' connect to the Access database
Set cn = New ADODB.Connection
myConn = TARGET_DB
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open myConn
End With
Set rs = New ADODB.Recordset
src = "SELECT * FROM tblClasses WHERE ID=" & Me.cboClasses.Column(5) & ""
rs.Open src, cn, adOpenKeyset, adLockOptimistic, adCmdText
If Me.chkClasses.Value = True Then
.Fields("disClass").Value = True
Else: .Fields("disClass").Value = False
End If
rs.Update
End With
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
Exit Sub
End Sub