Saving data in userforms on action

E

Eric Larsen

I am using a userform with listboxes that the user enters data into and than
another userform that returns the calculated results. I would like to know
the code to retain text that was entered in each listbox (in the registry or
whatever) on the press of an action button.

Here is JW's solution but I get an error improper use of Me function or
something similar when I use it.

'Sub Getdefaults()

' Dim ctl As Control
' Dim Ctrltype As String

' For Each ctl In Me.Controls
'Ctrltype = TypeName(ctl)
'If Ctrltype = "Textbox" Or _
'"Combobox" Or _
'"Optionbox" Or _
'"Checkbox" Or _
'"Spinbutton" Then
'ctl.Value = GetSetting _
'(APPNAME, "Defaults", ctl.Name, ctl.Value)
'End If
'Next ctl
'End Sub
'Sub SaveDefaults()

' Dim ctl As Control
' Dim Ctrltype As String

' For Each ctl In Me.Controls
'Ctrltype = TypeName(ctl)
'If Ctrltype = "Textbox" Or _
'"Combobox" Or _
'"Optionbox" Or _
'"Checkbox" Or _
'"Spinbutton" Then
'SaveSetting APPNAME, _
'"Defaults", ctl.Name, ctl.Value
'End If
'Next ctl
'End Sub

Any thoughts?

Thanks in advance
 
D

Daniel Klann

-----Original Message-----
I am using a userform with listboxes that the user enters data into and than
another userform that returns the calculated results. I would like to know
the code to retain text that was entered in each listbox (in the registry or
whatever) on the press of an action button.

Here is JW's solution but I get an error improper use of Me function or
something similar when I use it.

'Sub Getdefaults()

' Dim ctl As Control
' Dim Ctrltype As String

' For Each ctl In Me.Controls
'Ctrltype = TypeName(ctl)
'If Ctrltype = "Textbox" Or _
'"Combobox" Or _
'"Optionbox" Or _
'"Checkbox" Or _
'"Spinbutton" Then
'ctl.Value = GetSetting _
'(APPNAME, "Defaults", ctl.Name, ctl.Value)
'End If
'Next ctl
'End Sub
'Sub SaveDefaults()

' Dim ctl As Control
' Dim Ctrltype As String

' For Each ctl In Me.Controls
'Ctrltype = TypeName(ctl)
'If Ctrltype = "Textbox" Or _
'"Combobox" Or _
'"Optionbox" Or _
'"Checkbox" Or _
'"Spinbutton" Then
'SaveSetting APPNAME, _
'"Defaults", ctl.Name, ctl.Value
'End If
'Next ctl
'End Sub

Any thoughts?

Thanks in advance

Hi,

You just have a slight error in your If statement. You
cannot say for example:-

IF A=1 or 2 or 3 then B=2

You need to say

IF A=1 or A=2 or A=3 then B=2.

Here is the code I used. Notice that I specified Option
Compare Text (because Textbox2<>TextBox2 otherwise) and
defined APPNAME.

Regards,
Daniel
http://www.danielklann.com

Option Compare Text
Const APPNAME = "My App"

Sub Getdefaults()

Dim ctl As Control
Dim Ctrltype As String

For Each ctl In Me.Controls
Ctrltype = TypeName(ctl)
If Ctrltype = "Textbox" Or _
Ctrltype = "Combobox" Or _
Ctrltype = "Optionbox" Or _
Ctrltype = "Checkbox" Or _
Ctrltype = "Spinbutton" Then
ctl.Value = GetSetting _
(APPNAME, "Defaults", ctl.Name,
ctl.Value)
End If
Next ctl
End Sub
Sub SaveDefaults()

Dim ctl As Control
Dim Ctrltype As String

For Each ctl In Me.Controls
Ctrltype = TypeName(ctl)
If Ctrltype = "Textbox" Or _
Ctrltype = "Combobox" Or _
Ctrltype = "Optionbox" Or _
Ctrltype = "Checkbox" Or _
Ctrltype = "Spinbutton" Then
SaveSetting APPNAME, _
"Defaults", ctl.Name, ctl.Value
End If
Next ctl
End Sub
 

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