Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default setting focus to particular textbox

Is it possible to add a line of code to a command button to set the focus to
a particular textbox, so it ready for the user to type there?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default setting focus to particular textbox

Range("D1").Select


"Charlie" wrote:

Is it possible to add a line of code to a command button to set the focus to
a particular textbox, so it ready for the user to type there?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default setting focus to particular textbox

I tried:
Range(rownumber,1).Select
....but get an error. I wanting the cursor to be in the textbox TxName, on
the active userform, not on the sheet itself.


"Joel" wrote:

Range("D1").Select


"Charlie" wrote:

Is it possible to add a line of code to a command button to set the focus to
a particular textbox, so it ready for the user to type there?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default setting focus to particular textbox

I don't have the answer. Found in VBA help the following but it doesn't
work. I think you need a form

TextBox Control, SetFocus Method, EnterFieldBehavior, HideSelection,
MultiLine, Value Properties Example

'

The following example demonstrates the HideSelection property in the context
of either a single form or more than one form. The user can select text in a
TextBox and TAB to other controls on a form, as well as transfer the focus to
a second form. This code sample also uses the SetFocus method, and the
EnterFieldBehavior, MultiLine, and Value properties.

To use this example, follow these steps:

Copy this sample code (except for the last event subroutine) to the
Declarations portion of a form.


Add a large TextBox named TextBox1, a ToggleButton named ToggleButton1, and
a CommandButton named CommandButton1.


Insert a second form into this project named UserForm2.


Paste the last event subroutine of this listing into the Declarations
section of UserForm2.


In this form, add a CommandButton named CommandButton1.


Run UserForm1.
' ***** Code for UserForm1 *****

Private Sub CommandButton1_Click()
TextBox1.SetFocus
UserForm2.Show 'Bring up the second form.
End Sub
Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
TextBox1.HideSelection = False
ToggleButton1.Caption = "Selection Visible"
Else
TextBox1.HideSelection = True
ToggleButton1.Caption = "Selection Hidden"
End If
End Sub
Private Sub UserForm_Initialize()
TextBox1.MultiLine = True
TextBox1.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection

'Fill the TextBox
TextBox1.Text = "SelText indicates the starting " _
& "point of selected text, or the insertion " _
& point if no text is selected." & Chr$(10) _
& Chr$(13) & "The SelStart property is " _
& "always valid, even when the control does " _
& "not have focus. Setting SelStart to a " _
& "value less than zero creates an error. " _
& Chr$(10) & Chr$(13) & "Changing the value " _
& "of SelStart cancels any existing " _
& "selection in the control, places " _
& "an insertion point in the text, and sets " _
& "the SelLength property to zero."

TextBox1.HideSelection = True
ToggleButton1.Caption = "Selection Hidden"
ToggleButton1.Value = False

End Sub
'


' ***** Code for UserForm2 *****

Private Sub CommandButton1_Click()
UserForm2.Hide
End Sub


"Charlie" wrote:

I tried:
Range(rownumber,1).Select
...but get an error. I wanting the cursor to be in the textbox TxName, on
the active userform, not on the sheet itself.


"Joel" wrote:

Range("D1").Select


"Charlie" wrote:

Is it possible to add a line of code to a command button to set the focus to
a particular textbox, so it ready for the user to type there?

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
TextBox focus 2 Tim Coddington Excel Programming 2 July 28th 04 05:15 AM
textbox focus Arne Excel Programming 1 June 15th 04 10:44 AM
TextBox Focus Tom Ogilvy Excel Programming 0 June 3rd 04 05:58 PM
TextBox Focus Tom Ogilvy Excel Programming 0 June 3rd 04 04:55 PM
TextBox focus Tom Ogilvy Excel Programming 0 June 3rd 04 03:17 PM


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