changing the controls for a userform

B

baha17

Hi Everyone,
I have a userform which there are too many textboxes something like
500. Depends on the resolution, I need to alter them sometimes even
need to create them all over again.I have to give them a specific Name
to work with my codes.Here is my question, is there any way that I can
change their names automatically with a macro. I know it is not
possible in runtime, but it's so hard to rename those textboxes all
over again whenever I need to alter. Just for your reference those
textbox names goes like

Gm1txt1,Gm1txt2,Gm1txt3,Gm1txt4,.....Gm1txt15 then next column
Gm2txt1,Gm2txt2,Gm2txt3,Gm2txt4,.....Gm2txt15
Gm3txt1,Gm3txt2,Gm3txt3,Gm3txt4,.....Gm3txt15
..
..
Gm38txt1,Gm38txt2,Gm38txt3,Gm38txt4,.....Gm38txt15

Thanks in advance,
Baha
 
G

GS

(e-mail address removed) pretended :
Hi Everyone,
I have a userform which there are too many textboxes something like
500. Depends on the resolution, I need to alter them sometimes even
need to create them all over again.I have to give them a specific Name
to work with my codes.Here is my question, is there any way that I can
change their names automatically with a macro. I know it is not
possible in runtime, but it's so hard to rename those textboxes all
over again whenever I need to alter. Just for your reference those
textbox names goes like

Gm1txt1,Gm1txt2,Gm1txt3,Gm1txt4,.....Gm1txt15 then next column
Gm2txt1,Gm2txt2,Gm2txt3,Gm2txt4,.....Gm2txt15
Gm3txt1,Gm3txt2,Gm3txt3,Gm3txt4,.....Gm3txt15
.
.
Gm38txt1,Gm38txt2,Gm38txt3,Gm38txt4,.....Gm38txt15

Thanks in advance,
Baha

Would doing something like this work for you...?

Use the 15 textboxes only. Put the GM# in a combobox. User selects GM#
from combobox, textboxes appropriately clear (or populate with default
data), and your code is modified to process the inputs according to the
value selected in the combobox.

Alternatively, if your app cycles through the GM#s automatically then
reset your code to process with the new GM#.

Note that this concept allows you to reuse the same procedure for
each iteration, OR call GM#-specific procedures as required.

HTH
 
B

baha17

Hi Gary,

Thanks for the reply but I am afraid I could not understand you
clearly.Is there any way you give me more details?
thanks
Baha
 
G

GS

(e-mail address removed) was thinking very hard :
Hi Gary,

Thanks for the reply but I am afraid I could not understand you
clearly.Is there any way you give me more details?
thanks
Baha

Okay, I'll try this again!

It appears that you are providing textboxes for user input on a form.
There are 15 textboxes for each group of data. There are 38 groups.
This is my understanding so far!

Using only 15 textboxes (instead of 15x38 [570]) keeps things simple
and efficient to manage. Using a loop to iterate each value could also
keep things simple and efficient to manage.

Using a combobox so users can randomly select which group they want to
input data for is also simple and efficient to manage. When an item is
selected the textboxes are cleared (or populated with existing data for
the selected group), and the selection is loaded into a variable to
hold the current selected group.

Use an array to load each textbox value into,

'Declare module-level variables
Dim msaDataArray(16) As String, msCurrentGroup As String

ComboBox1_Change()
msCurrentGroup = Me.ComboBox1.Text
msaDataArray(0) = msCurrentGroup
End Sub

Use the Exit event to load each element of the array according to
texbox. For example, the code in textbox1 would be something like this:

TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
myDataArray(CInt(Me.TextBox1.Tag)) = Me.TextBox1.Text
'where "1" is the Tag property for textbox1
End Sub

Code for textbox2_Exit event...
myDataArray(CInt(Me.TextBox1.Tag) = Me.TextBox2.Text
'where "2" is the Tag property for textbox2
...and so on

Provide a button so the user can process the data for the selected
group after all data is input. When this button is clicked, have code
to process the array and clear its elements for the next set of data.
Optionally, you could include code to clear the array in the
ComboBax1_Change() event, as a means to 'reset' the textboxes and array
for/with values for the new selection.

*******************************************************
If populating textboxes with default or existing values
*******************************************************
This would require a means of storing/retrieving the data for each
group, which you may already have in place. If the textboxes are
'Bound' to their data sources then any changes will update the data
source. I don't suspect this is what you're doing so iterating the
array is probably the easiest way to store/retrieve the data. Using a
UDT might even be easier depending on how/where/if the data is stored.
In this scenario you would populate the textboxes with their respective
stored data, which also is loaded into the array. The idea here is to
read data into the array and from there populate the textboxes
according to their index in the array. Since VBA doesn't support
control arrays, it might be simpler to manage by coding for each
textbox directly from the array. Example:

TextBox1.Text = msaDataArray(1)
TextBox2.Text = msaDataArray(2)
...and so on

The exit event will update the array. Write the array back to the
storage to update that.

**************
Final Comments
**************
If the number of textboxes is variable then you can hide/show
accordingly if you create the max number expected at design time. This
can be managed in the ComboBox_Change() event.

If the data isn't stored anywhere, but just processed on the spot then
this concept of reusing the textboxes for each selected group is even
easier to implement.

All you need to do is track which group the current set of data belongs
to, and process accordingly!

HTH
 
B

baha17

Gary,

Thank you for the reply. However that user from should be that many
textbox. Because that is the for the new game display in my casino. I
tried to make a grinds in the userform that's why I prepare that many
textbox.I am using excel 2003 and that's the only way that I think of
so far. There are endless game entries for the user which prompt by
the numberpad by (1,2,3 etc..).After every 38 games it clears all
textbox entries and reloads again. That is the whole story. That's why
I cannot use combo boxes.
I think I have no choice that I need to enter manually each time I
design the textboxes.
Thank you very much for your answer again.
Merry Christmas and Happy New Year

Baha
 

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