User forms

E

eklarsen

I posted this earlier and did not get a response, I will try t
clarify..

I am using a userform with listboxes that the user enters data into an
than another userform that returns the calculated results. I would lik
to know the code to retain text that was entered in each listbox (i
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 o
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 advanc
 
C

chris

You could use a Public 2 dimensional Array to store the Listbox names and Values
But where is this On action Button? The Me.Controls assumes you are calling the procedure from the form where the controls are on

At the top of a Module Put this
Public MyArray() As Strin

But this code will have to be called from the form's modul

Dim Lstbx As MSForms.ListBox, i As Singl
For Each ctrl In Me.Control
If TypeOf ctrl Is MSForms.ListBox The
Set Lstbx = ctrl
ReDim Preserve MyArray(0 to1,i) ' << assumes Option Base
MyArray(0,i)= Lstbx.Nam
MyArray(1,i)= Lstbx.Tex
i = i +
End I
Next

MyArray will now hold all the values for your list boxes after the form is closed

----- eklarsen > wrote: ----

I posted this earlier and did not get a response, I will try t
clarify.

I am using a userform with listboxes that the user enters data into an
than another userform that returns the calculated results. I would lik
to know the code to retain text that was entered in each listbox (i
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 o
something similar when I use it

'Sub Getdefaults(

' Dim ctl As Contro
' Dim Ctrltype As Strin

' For Each ctl In Me.Control
'Ctrltype = TypeName(ctl
'If Ctrltype = "Textbox" Or
'"Combobox" Or
'"Optionbox" Or
'"Checkbox" Or
'"Spinbutton" The
'ctl.Value = GetSetting
'(APPNAME, "Defaults", ctl.Name, ctl.Value
'End I
'Next ct
'End Su
'Sub SaveDefaults(

' Dim ctl As Contro
' Dim Ctrltype As Strin

' For Each ctl In Me.Control
'Ctrltype = TypeName(ctl
'If Ctrltype = "Textbox" Or
'"Combobox" Or
'"Optionbox" Or
'"Checkbox" Or
'"Spinbutton" The
'SaveSetting APPNAME,
'"Defaults", ctl.Name, ctl.Valu
'End I
'Next ct
'End Su

Any thoughts

Thanks in advanc
 
E

eklarsen

Thank you for your reply.

Will I then need to call the Array to repopulate when the form i
re-opened?

Perhaps using a on activate or something
 
C

chris

Yes: You can use this to repopulate the for
This also has to be run from within the form's Modul

Dim i As Singl
For i = 0 to Ubound(MyArray
Me.Controls(MyArray(0,i)).Text = MyArray(1,i
Nex

----- eklarsen > wrote: ----

Thank you for your reply

Will I then need to call the Array to repopulate when the form i
re-opened

Perhaps using a on activate or something
 
C

chris

Oh, 1 more thing, it would make sense to clear the array each time before its reused, so do this for the first code

Dim Lstbx As MSForms.ListBox, i As Singl
ReDim MyArray() '<< Add this lin
For Each ctrl In Me.Control
If TypeOf ctrl Is MSForms.ListBox The
Set Lstbx = ctrl
ReDim Preserve MyArray(0 to1,i) ' << assumes Option Base
MyArray(0,i)= Lstbx.Nam
MyArray(1,i)= Lstbx.Tex
i = i +
End I
Next

----- chris wrote: ----

Yes: You can use this to repopulate the for
This also has to be run from within the form's Modul

Dim i As Singl
For i = 0 to Ubound(MyArray
Me.Controls(MyArray(0,i)).Text = MyArray(1,i
Nex

----- eklarsen > wrote: ----

Thank you for your reply

Will I then need to call the Array to repopulate when the form i
re-opened

Perhaps using a on activate or something
 
C

chris: Correction

ReDim MyArray() won't work
Use This : ReDim MyArray(0,0
There is a Method just to clear an array but i can't remember it right now! This will work Anyhoo
 

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