Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default TextBox Click Event

Hi Dave
Thanks for the code.
I see the principle, but can't get it to run.
I loaded it as per your instructions.
It hangs at:-
ReDim Preserve TBoxes(1 To TBoxCtr)
with the error message "variable not defined".
I note that the only definition reference to TBoxes is
Dim TBoxes() As New Class1
which is outside the Userform Initialize Subroutine.
What am I missing here.
donwb


"Dave Peterson" wrote in message
...
John Walkenbach explains how to do this using a class module:
http://spreadsheetpage.com/index.php...one_procedure/

You'll want to insert a class module in the workbook's project
(Insert|class module in the VBE).

It'll be named Class1 (unless you rename it or add more).

I used Class1 in this example.

This code goes into the class module:

Option Explicit
Public WithEvents TBoxGroup As MSForms.TextBox
Private Sub TBoxGroup_Change()
MsgBox TBoxGroup.Name & vbLf & "changed"
End Sub
Private Sub TBoxGroup_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = xlSecondaryButton Then
MsgBox TBoxGroup.Name & vbLf & "had the rightclick button pressed"
Else
MsgBox TBoxGroup.Name & vbLf & "not the rightclick button"
End If
End Sub

Then inside the userform module:

Option Explicit
Dim TBoxes() As New Class1
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()

Dim ctl As Control
Dim TBoxCtr As Long

TBoxCtr = 0
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
TBoxCtr = TBoxCtr + 1
ReDim Preserve TBoxes(1 To TBoxCtr)
Set TBoxes(TBoxCtr).TBoxGroup = ctl
End If
Next ctl

End Sub


Then show the userform and test it out.





donwb wrote:

Win XP, Excel2003

I have a UserForm populated with many TextBoxes.
Is there an event or trigger which is fired when ANY of
the TextBoxes is clicked apart, of course, from the box itself?
I could do it by writing suitable code for each box,
but am trying to avoid this as there are too many.
donwb


--

Dave Peterson



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default TextBox Click Event

Either the tboxctr is incorrectly declared or the tboxes is.

Try it in a brand new workbook. Maybe the code was commingled with your
existing code and you didn't put it in the right spot????



donwb wrote:

Hi Dave
Thanks for the code.
I see the principle, but can't get it to run.
I loaded it as per your instructions.
It hangs at:-
ReDim Preserve TBoxes(1 To TBoxCtr)
with the error message "variable not defined".
I note that the only definition reference to TBoxes is
Dim TBoxes() As New Class1
which is outside the Userform Initialize Subroutine.
What am I missing here.
donwb

"Dave Peterson" wrote in message
...
John Walkenbach explains how to do this using a class module:
http://spreadsheetpage.com/index.php...one_procedure/

You'll want to insert a class module in the workbook's project
(Insert|class module in the VBE).

It'll be named Class1 (unless you rename it or add more).

I used Class1 in this example.

This code goes into the class module:

Option Explicit
Public WithEvents TBoxGroup As MSForms.TextBox
Private Sub TBoxGroup_Change()
MsgBox TBoxGroup.Name & vbLf & "changed"
End Sub
Private Sub TBoxGroup_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = xlSecondaryButton Then
MsgBox TBoxGroup.Name & vbLf & "had the rightclick button pressed"
Else
MsgBox TBoxGroup.Name & vbLf & "not the rightclick button"
End If
End Sub

Then inside the userform module:

Option Explicit
Dim TBoxes() As New Class1
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()

Dim ctl As Control
Dim TBoxCtr As Long

TBoxCtr = 0
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
TBoxCtr = TBoxCtr + 1
ReDim Preserve TBoxes(1 To TBoxCtr)
Set TBoxes(TBoxCtr).TBoxGroup = ctl
End If
Next ctl

End Sub


Then show the userform and test it out.





donwb wrote:

Win XP, Excel2003

I have a UserForm populated with many TextBoxes.
Is there an event or trigger which is fired when ANY of
the TextBoxes is clicked apart, of course, from the box itself?
I could do it by writing suitable code for each box,
but am trying to avoid this as there are too many.
donwb


--

Dave Peterson


--

Dave Peterson
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
adding right click menu to textbox אלי Excel Programming 3 July 3rd 07 06:46 AM
Click event on menu item is lost after first time firing of the event [email protected] Excel Programming 1 April 2nd 07 01:25 PM
Can you Click the "Enter" key to go to the next line in a Textbox without Exiting the Textbox ? Corey Excel Programming 1 February 22nd 07 05:09 AM
set textbox cursor in mouse right-click RB Smissaert Excel Programming 11 November 5th 06 05:06 PM
userform label double-click goes to click event John Paul Fullerton Excel Programming 3 May 19th 06 05:54 PM


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