-
Oct 23rd, 2008, 12:57 PM
#1
Thread Starter
Member
[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
-
Oct 23rd, 2008, 03:24 PM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 23rd, 2008, 10:01 PM
#3
Thread Starter
Member
Re: [Excel] Repeat savesettings for every control in form
Not sure how to do this, please show some code as example? Thx
-
Oct 24th, 2008, 05:19 AM
#4
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 24th, 2008, 06:00 AM
#5
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
-
Oct 24th, 2008, 06:08 AM
#6
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)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 24th, 2008, 08:38 AM
#7
Thread Starter
Member
Re: [Excel] Repeat savesettings for every control in form
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|