Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Addressing specific textboxes on a form

I have a userform with 100 textboxes on it and another form with 100
labels. The textboxes are filled with numbers 1 to 26.

I want to change the label captions on the second form to the alpha
equivalent of the number in the textbox, ie if textbox 27 has 5 in it,
the caption for label 27 should be E.

Also if I change say textbox 45 from 7 to 22, I want this cahnge to be
reflected in the caption for label 45.

I understand this could be done through control arrays but I can't get
them to work for textboxes.

Could someone help please?
Thanks
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Addressing specific textboxes on a form

Chris,

The chief problem is that form controls in a class don't have Exit or
AfterUpdate events, so validation is difficult, because you have to use the
Change event. Beyond that, I think I was able to get what you want:

Assuming:
UserForm1 and UserForm2: with TextBox1 ... TextBox100 and Label1...
Label100, respectively
A class module called "FormTboxClass"
A standard module

In the FormTboxClass this code:

Public WithEvents FormTbox As msforms.TextBox
Private Sub FormTbox_Change()

With FormTbox
If IsNumeric(.Value) Then
If .Value = 1 And .Value <= 26 Then
UserForm2.Controls("Label" & Mid(FormTbox.Name, 8)).Caption =
Chr(FormTbox.Value + 64)
End If
End If
End With
End Sub

In UserForm1 this code:

Dim myControls As Collection ' note this is above any subroutines
Option Explicit
Private Sub UserForm_Initialize()

Dim tmpctl As Control
Dim ctl As FormTboxClass

Set myControls = New Collection
For Each tmpctl In Me.Controls
If TypeOf tmpctl Is msforms.TextBox Then
Set ctl = New FormTboxClass
Set ctl.FormTbox = tmpctl
myControls.Add ctl
End If
Next

End Sub

In the standard module this code:

Sub test()

UserForm1.Show modeless
UserForm2.Show modeless

End Sub

Run the "test" macro. Move Form2 to reveal Form1. You should get the
actions you described. Notice that if you go outside the range 1 to 26 or
enter non-numeric characters, nothing happens. I tried to do more with
invalid entries, but couldn't find a good solution. I think the forms have
to be modeless for this to work, but not positive.

hth,

Doug

"inquirer" wrote in message
u...
I have a userform with 100 textboxes on it and another form with 100
labels. The textboxes are filled with numbers 1 to 26.

I want to change the label captions on the second form to the alpha
equivalent of the number in the textbox, ie if textbox 27 has 5 in it, the
caption for label 27 should be E.

Also if I change say textbox 45 from 7 to 22, I want this cahnge to be
reflected in the caption for label 45.

I understand this could be done through control arrays but I can't get
them to work for textboxes.

Could someone help please?
Thanks
Chris



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Addressing specific textboxes on a form

Doug Glancy wrote:
Chris,

The chief problem is that form controls in a class don't have Exit or
AfterUpdate events, so validation is difficult, because you have to use the
Change event. Beyond that, I think I was able to get what you want:

Assuming:
UserForm1 and UserForm2: with TextBox1 ... TextBox100 and Label1...
Label100, respectively
A class module called "FormTboxClass"
A standard module

In the FormTboxClass this code:

Public WithEvents FormTbox As msforms.TextBox
Private Sub FormTbox_Change()

With FormTbox
If IsNumeric(.Value) Then
If .Value = 1 And .Value <= 26 Then
UserForm2.Controls("Label" & Mid(FormTbox.Name, 8)).Caption =
Chr(FormTbox.Value + 64)
End If
End If
End With
End Sub

In UserForm1 this code:

Dim myControls As Collection ' note this is above any subroutines
Option Explicit
Private Sub UserForm_Initialize()

Dim tmpctl As Control
Dim ctl As FormTboxClass

Set myControls = New Collection
For Each tmpctl In Me.Controls
If TypeOf tmpctl Is msforms.TextBox Then
Set ctl = New FormTboxClass
Set ctl.FormTbox = tmpctl
myControls.Add ctl
End If
Next

End Sub

In the standard module this code:

Sub test()

UserForm1.Show modeless
UserForm2.Show modeless

End Sub

Run the "test" macro. Move Form2 to reveal Form1. You should get the
actions you described. Notice that if you go outside the range 1 to 26 or
enter non-numeric characters, nothing happens. I tried to do more with
invalid entries, but couldn't find a good solution. I think the forms have
to be modeless for this to work, but not positive.

hth,

Doug

"inquirer" wrote in message
u...

I have a userform with 100 textboxes on it and another form with 100
labels. The textboxes are filled with numbers 1 to 26.

I want to change the label captions on the second form to the alpha
equivalent of the number in the textbox, ie if textbox 27 has 5 in it, the
caption for label 27 should be E.

Also if I change say textbox 45 from 7 to 22, I want this cahnge to be
reflected in the caption for label 45.

I understand this could be done through control arrays but I can't get
them to work for textboxes.

Could someone help please?
Thanks
Chris




Thanks Doug.
I tried that and it seems ok but for one thing - I can't enter more than
1 digit in the first userform - as soon as I try to enter say 11, it
accepts the first 1 then tries to insert a 1 in the code for the
formtboxclass.

The other thing I wanted to do was evaluate an integer j in the test
module code and then substitute Chr(j + 64)
in label(j).caption
Will
UserForm2.Controls("Label" & j).Caption = Chr(j + 64)
do that for me?

Thanks
Chris
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Addressing specific textboxes on a form

Doug
"inquirer" wrote in message
...
Doug Glancy wrote:
Chris,

The chief problem is that form controls in a class don't have Exit or
AfterUpdate events, so validation is difficult, because you have to use
the Change event. Beyond that, I think I was able to get what you want:

Assuming:
UserForm1 and UserForm2: with TextBox1 ... TextBox100 and Label1...
Label100, respectively
A class module called "FormTboxClass"
A standard module

In the FormTboxClass this code:

Public WithEvents FormTbox As msforms.TextBox
Private Sub FormTbox_Change()

With FormTbox
If IsNumeric(.Value) Then
If .Value = 1 And .Value <= 26 Then
UserForm2.Controls("Label" & Mid(FormTbox.Name, 8)).Caption =
Chr(FormTbox.Value + 64)
End If
End If
End With
End Sub

In UserForm1 this code:

Dim myControls As Collection ' note this is above any subroutines
Option Explicit
Private Sub UserForm_Initialize()

Dim tmpctl As Control
Dim ctl As FormTboxClass

Set myControls = New Collection
For Each tmpctl In Me.Controls
If TypeOf tmpctl Is msforms.TextBox Then
Set ctl = New FormTboxClass
Set ctl.FormTbox = tmpctl
myControls.Add ctl
End If
Next

End Sub

In the standard module this code:

Sub test()

UserForm1.Show modeless
UserForm2.Show modeless

End Sub

Run the "test" macro. Move Form2 to reveal Form1. You should get the
actions you described. Notice that if you go outside the range 1 to 26
or enter non-numeric characters, nothing happens. I tried to do more
with invalid entries, but couldn't find a good solution. I think the
forms have to be modeless for this to work, but not positive.

hth,

Doug

"inquirer" wrote in message
u...

I have a userform with 100 textboxes on it and another form with 100
labels. The textboxes are filled with numbers 1 to 26.

I want to change the label captions on the second form to the alpha
equivalent of the number in the textbox, ie if textbox 27 has 5 in it,
the caption for label 27 should be E.

Also if I change say textbox 45 from 7 to 22, I want this cahnge to be
reflected in the caption for label 45.

I understand this could be done through control arrays but I can't get
them to work for textboxes.

Could someone help please?
Thanks
Chris




Thanks Doug.
I tried that and it seems ok but for one thing - I can't enter more than 1
digit in the first userform - as soon as I try to enter say 11, it accepts
the first 1 then tries to insert a 1 in the code for the formtboxclass.


I was able to enter 2 digits as long as the overall number was in the range
1 to 26. But because I used the Change event, the letters in changed with
every digit typed. Since no Exit or AfterUpdate event is available in the
Class textbox, I don't know how to avoid this. Are you never able to enter
the second digit?

The other thing I wanted to do was evaluate an integer j in the test
module code and then substitute Chr(j + 64)
in label(j).caption
Will
UserForm2.Controls("Label" & j).Caption = Chr(j + 64)
do that for me?

I think so, but I'd need to see the code in order to try to answer.

Thanks
Chris


Doug


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Addressing specific textboxes on a form

Doug Glancy wrote:
Doug
"inquirer" wrote in message
...

Doug Glancy wrote:

Chris,

The chief problem is that form controls in a class don't have Exit or
AfterUpdate events, so validation is difficult, because you have to use
the Change event. Beyond that, I think I was able to get what you want:

Assuming:
UserForm1 and UserForm2: with TextBox1 ... TextBox100 and Label1...
Label100, respectively
A class module called "FormTboxClass"
A standard module

In the FormTboxClass this code:

Public WithEvents FormTbox As msforms.TextBox
Private Sub FormTbox_Change()

With FormTbox
If IsNumeric(.Value) Then
If .Value = 1 And .Value <= 26 Then
UserForm2.Controls("Label" & Mid(FormTbox.Name, 8)).Caption =
Chr(FormTbox.Value + 64)
End If
End If
End With
End Sub

In UserForm1 this code:

Dim myControls As Collection ' note this is above any subroutines
Option Explicit
Private Sub UserForm_Initialize()

Dim tmpctl As Control
Dim ctl As FormTboxClass

Set myControls = New Collection
For Each tmpctl In Me.Controls
If TypeOf tmpctl Is msforms.TextBox Then
Set ctl = New FormTboxClass
Set ctl.FormTbox = tmpctl
myControls.Add ctl
End If
Next

End Sub

In the standard module this code:

Sub test()

UserForm1.Show modeless
UserForm2.Show modeless

End Sub

Run the "test" macro. Move Form2 to reveal Form1. You should get the
actions you described. Notice that if you go outside the range 1 to 26
or enter non-numeric characters, nothing happens. I tried to do more
with invalid entries, but couldn't find a good solution. I think the
forms have to be modeless for this to work, but not positive.

hth,

Doug

"inquirer" wrote in message
m.au...


I have a userform with 100 textboxes on it and another form with 100
labels. The textboxes are filled with numbers 1 to 26.

I want to change the label captions on the second form to the alpha
equivalent of the number in the textbox, ie if textbox 27 has 5 in it,
the caption for label 27 should be E.

Also if I change say textbox 45 from 7 to 22, I want this cahnge to be
reflected in the caption for label 45.

I understand this could be done through control arrays but I can't get
them to work for textboxes.

Could someone help please?
Thanks
Chris



Thanks Doug.
I tried that and it seems ok but for one thing - I can't enter more than 1
digit in the first userform - as soon as I try to enter say 11, it accepts
the first 1 then tries to insert a 1 in the code for the formtboxclass.



I was able to enter 2 digits as long as the overall number was in the range
1 to 26. But because I used the Change event, the letters in changed with
every digit typed. Since no Exit or AfterUpdate event is available in the
Class textbox, I don't know how to avoid this. Are you never able to enter
the second digit?


I can not enter more than 1 digit without triggering the FormTbox check
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
fill a form with specific data Carla Excel Worksheet Functions 7 October 27th 09 10:49 PM
clear specific cells in a form vdmbqb Excel Discussion (Misc queries) 1 November 24th 07 08:07 PM
Hyperlink to specific Form in MSAccess Widemonk Excel Discussion (Misc queries) 4 January 25th 06 10:15 PM
TextBoxes on a Form Neil Excel Programming 4 June 4th 04 01:25 PM
Form Textboxes Pat[_11_] Excel Programming 1 February 3rd 04 09:42 PM


All times are GMT +1. The time now is 04:40 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"