#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default User forms

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

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default User forms

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


--
Message posted from http://www.ExcelForum.com


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default User forms

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

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default User forms

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


--
Message posted from http://www.ExcelForum.com


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default User forms

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


--
Message posted from http://www.ExcelForum.com




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default User forms

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New to User Forms Stacy New Users to Excel 2 July 30th 08 04:26 PM
User Forms Joanne New Users to Excel 18 July 5th 07 12:42 AM
User forms eklarsen[_4_] Excel Programming 2 May 6th 04 06:09 PM
User forms Scott Excel Programming 4 April 18th 04 06:22 PM
User forms Candee[_2_] Excel Programming 2 September 12th 03 03:11 PM


All times are GMT +1. The time now is 12:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"