Show checkbox checked on open

S

Solution4U

I need help.

I have 3 userforms. Userform1 has 2 buttons, one to start a new project and
one that edits the project as saved. Which ever button is clicked brings up
userform2 which has 5 checkboxes.

What I would like to happen: when the edit button is clicked I would like
the checkboxes that were checked the last time to show up as checked. The
value of the checkboxes are stored on sheet3 in cells c2-c6.

Thank you for your time and assistance.
 
J

JLGWhiz

You could probably set up a linked cell (control source) for each checkbox
which would hold the value of the checkbox until the form is reopened and
will show that value upon open.
 
S

Solution4U

Could you show me an example of code for that? I am rather new to vba.

Thank you for the response.
 
J

john

I would save setting values to registry.

paste this code in a standard module: (rename Userform1 as appropriate)


Sub GetSettings()
' Reads default settings from the registry
Dim ctl As Control
Dim CtrlType As String

For Each ctl In UserForm1.Controls
CtrlType = TypeName(ctl)
If CtrlType = "CheckBox" Then

ctl.Value = GetSetting(AppName:="My Application", _
section:="CheckBox Settings", _
key:=ctl.Name, Default:=False)

End If
Next ctl
End Sub

Sub SaveSettings()
' Writes current settings to the registry
Dim ctl As Control
Dim CtrlType As String

For Each ctl In UserForm1.Controls
CtrlType = TypeName(ctl)
If CtrlType = "CheckBox" Then

SaveSetting AppName:="My Application", _
section:="CheckBox Settings", key:=ctl.Name, _
setting:=CStr(ctl.Value)

End If
Next ctl
End Sub

then add this code to the userform with checkboxes:


Private Sub EditButton_Click()
SaveSettings
'other code
End Sub

Private Sub UserForm_Initialize()
GetSettings
'other code
End Sub

hope helps
 
J

JLGWhiz

The method suggested does not require code. In the properties dialog box for
each checkbox there is a Control Source property. Select that property and
type in a cell reference e.g. Sheet1!a1. Of course use a different cell
for each checkbox, and choose a cell that will not be accesssed by users in
the normal course of business to avoid inadvertant changes. The chosen cells
will show True if the checkbox is checked and False if the checkbox is blank.
These cell values are retained after the userform is closed and are
automatically loaded into the checkbox when the userform is initialized again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top