VBA Userform Checkbox - How to return checkbox (checked) when DB record shows checkbox is True

Roe_01

New Member
Joined
Feb 12, 2023
Messages
7
Office Version
  1. 2019
Platform
  1. Windows
Hello -
I have a feeling there is a simple solution for my question. I have a checkbox on my userform and when I save the record is saves the value as True or False in the DB which makes sense. However, when I edit the record, how do I show the checkbox being checked when the database shows the record as True.


2023-02-17_1-10-38.jpg


2023-02-17_1-00-00.jpg



Below is some of the code when I edit the record from the listbox but the last line is for the only checkbox on the userform. I know the code isn't correct and read a number of posts but couldn't find a solution.

Private Sub cmdEdit_Click()

If Selected_List = 0 Then

MsgBox "No row is selected.", vbOKOnly + vbInformation, "Edit"

Exit Sub
End If

'Code to update the value to respective controls
Me.txtRowNumber.Value = Application.WorksheetFunction.Match(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0), _
ThisWorkbook.Sheets("Database").Range("A:A"), 0)


txtBusCal17.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 122)
txtDueDate17.Value = Format(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 123), "mm/dd/yyyy")
txtComplete17.Value = Format(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 124), "mm/dd/yyyy")
CheckBox1.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 128)
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi,
Have you tested :
VBA Code:
Private Sub UserForm_Initialize()
  Me.CheckBox1.Value = Sheet1.Range("A1").Value
End Sub
 
Upvote 0
Solution
Hi James -
I appreciate the information and just tried it, but it didn't work. As you can see below, the record shows Inactive status but the checkbox is unchecked.

1676656211706.png
 
Upvote 0
Hi James -
I decided to use a txtStatus to drive the checkbox and it works. Thanks for your help.

txtStatus.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 1)

If txtStatus.Value = "Inactive" Then

CheckBox1.Value = True
Else

CheckBox1.Value = False

End If
 
Upvote 0

Forum statistics

Threads
1,214,824
Messages
6,121,783
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top