Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Which textbox have focus?

Private Sub TextBox1_Change()
convert_to_integer TextBox1
End Sub

Public Sub convert_to_integer(tbox as msforms.textbox)
If IsNumeric(Right(tbox.text, 1)) = False Then
Application.SendKeys "{BACKSPACE}"
End If

End Sub


But it would be better to use the keypress event.

See this post by Harald Staff (actually look at the thead)

http://groups.google.com/groups?thre...%40tkmsftngp05

You can use a single event to handle multiple textboxes using this technique
by John Walkenbach

http://j-walk.com/ss/excel/tips/tip44.htm
Handle Multiple UserForm Buttons With One Subroutine

It is written for commandbuttons, but works for textboxes and other msforms
2.0 controls as well.

--
Regards,
Tom Ogilvy




"kafka" wrote in message
...
Hi all.

I have 25 textbox in my user form and all textbox values must be
integer.
so i do it with this code

Private Sub TextBox1_Change()
If IsNumeric(Right(TextBox1, 1)) = False Then
Application.SendKeys "{BACKSPACE}"
End If
End Sub

As i said i have 25 textbox it takes a long time to write this code for
every text box on the user form.

Now i am trying make a procedure search all the texboxes which have
focus and make the above code.

For example

Private Sub TextBox1_Change()
convert_to_integer
End Sub


Public Sub convert_to_integer()
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "TextBox" Then
*If ctrl.SetFocus = True Then*
If IsNumeric(Right(ctrl, 1)) = False Then
Application.SendKeys "{BACKSPACE}"
End If
End If
End If
Next ctrl
End Sub

but this code givinme error on bold line "*If ctrl.SetFocus = True
Then* "

So how can i find the focused text box .

Thanks in advance.



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
Calculate Textbox value based on another textbox value.doc Tdungate Excel Discussion (Misc queries) 1 February 12th 09 07:11 PM
Calculate Textbox value based on another textbox value Tdungate Excel Discussion (Misc queries) 0 February 12th 09 07:03 PM
focus Capp Excel Discussion (Misc queries) 2 November 18th 05 07:25 PM
Focus David Unger Excel Worksheet Functions 20 March 21st 05 06:43 PM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM


All times are GMT +1. The time now is 10:09 PM.

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"