[RESOLVED] [Excel] Repeat savesettings for every control in form
Hi PeopleWithMuchMoreKnowledge
I would appreciate some assistance with this:
Before I open a form, I want to retrieve the last values of each control on it (only checkboxes). Similarly save all settings before closing the form.
The prooblem that I have is that the code only runs the for loop once and does not recocknize any controls on my form.
Sub routine called on opening form:
Code:
Public Sub CheckLastSettings(fileName As String, mySystemType As String)
On Error Resume Next
Dim myCheckBox As CheckBox
For Each myCheckBox In Me.Controls
myCheckBox.Value = GetSetting(fileName, mySystemType, myCheckBox, 0)
Next myCheckBox
End Sub
subroutine called on closing the form:
Code:
Public Sub SaveLastSettings(frmName As frmOptions, fileName As String, mySystemType As String)
On Error Resume Next
Dim myCheckBox As CheckBox
For Each myCheckBox In frmOptions.Controls
SaveSetting fileName, mySystemType, myCheckBox.Value, 0
Next myCheckBox
End Sub
The myChechbox variable created remains empty in both sub routines.
What am I missing?
Regards, Ossewa
Re: [Excel] Repeat savesettings for every control in form
you need to loop all controls, then savesetting if type is checkbox, or if name = check............, or if the control has a value property
Re: [Excel] Repeat savesettings for every control in form
Not sure how to do this, please show some code as example? Thx
Re: [Excel] Repeat savesettings for every control in form
this will save the value from all controls that have a value property, on error resume next to avoid error if any controls with no value property
vb Code:
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
SaveSetting "thisApp", "settings", c.Name, c.Value
Next
On Error GoTo 0
if you only want to save checkbox values use
if typename(c) = "CheckBox" then
Re: [Excel] Repeat savesettings for every control in form
If you want just checkboxs then
Code:
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is CheckBox Then
SaveSetting "thisApp", "settings", c.Name, c.Value
End If
Next
Re: [Excel] Repeat savesettings for every control in form
@ hack i tested with typeof, it worked for command button, but not checkbox (or other, i presume, forms2 controls)
Re: [Excel] Repeat savesettings for every control in form