Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default UserForm1.Textbox1.SetFocus Question

I have created a program in Excel 2000, which is used on a Windows 98,
Windows 2000 and Windows XP (Home Addition) platform. My problem is
the same on all platforms. The program contains 10 UserForms that
contain numerous Textboxes, comboboxes, listboxes, etc. Information is
entered into the textboxes and eventually transferred to forms for
printing, and a spreadsheet is used to maintain historical records.
Information fed into some of the textboxes is validated prior to the
user being able to continue to the next stage. When the user clicks
CommandButton1 the UserForm is hidden and the data entered validated.
If the data entered is invalid a MsgBox appears with a message
advising the user, who must then click the OK button to continue.
Upon clicking the OK button the unacceptable data that has been
entered in the textbox is erased and the UserForm re-appears so that
the user can enter the correct data. My problem is that I cannot get
the SETFOCUS command to activate the textbox when the UserForm
re-appears.

For example the Userform10 Code contains:

Private Sub commandbutton2_Click()
UserForm10.Hide
UserForm10.TextBox1.SetFocus
UserForm1.Show
End Sub

The UserForm1 Code contains:

Private Sub Commandbutton4_Click()
UserForm1.Hide
UserForm10.Show
UserForm10.TextBox1.SetFocus

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default UserForm1.Textbox1.SetFocus Question

Zane,

I think I get the general idea but the specific examples you show are not
clear to me as you seem to be bringing up different forms. Normally in a
single form you would do something like test the textbox value on exit and
if in error just highlight, like so

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(TextBox1.Text) 5 Then
MsgBox "Input must be less than 5 chars"
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
TextBox1.SetFocus
Cancel = True
End If
End Sub

If you do wish to bringt up a difefrent form, I suggest having variables in
that form to say which and use these in that form's activate event. For
instance in form1

Private Sub Commandbutton4_Click()
UserForm1.Hide
With UserForm10
.iTextBoxFocus = 2
.Show
End With
End Sub

Note the dor (.) before the iTextBoxFocus variable as this is referring to a
variable in form10

Then in form10, have something like

Public iTextBoxFocus As Long

Private Sub UserForm_Activate()
Select Case iTextBoxFocus
Case 2: TextBox2.SetFocus
Case 3: TextBox3.SetFocus
Case Else: TextBox1.SetFocus
End Select
End Sub

--

HTH

Bob Phillips

"Zane Greer" wrote in message
om...
I have created a program in Excel 2000, which is used on a Windows 98,
Windows 2000 and Windows XP (Home Addition) platform. My problem is
the same on all platforms. The program contains 10 UserForms that
contain numerous Textboxes, comboboxes, listboxes, etc. Information is
entered into the textboxes and eventually transferred to forms for
printing, and a spreadsheet is used to maintain historical records.
Information fed into some of the textboxes is validated prior to the
user being able to continue to the next stage. When the user clicks
CommandButton1 the UserForm is hidden and the data entered validated.
If the data entered is invalid a MsgBox appears with a message
advising the user, who must then click the OK button to continue.
Upon clicking the OK button the unacceptable data that has been
entered in the textbox is erased and the UserForm re-appears so that
the user can enter the correct data. My problem is that I cannot get
the SETFOCUS command to activate the textbox when the UserForm
re-appears.

For example the Userform10 Code contains:

Private Sub commandbutton2_Click()
UserForm10.Hide
UserForm10.TextBox1.SetFocus
UserForm1.Show
End Sub

The UserForm1 Code contains:

Private Sub Commandbutton4_Click()
UserForm1.Hide
UserForm10.Show
UserForm10.TextBox1.SetFocus

End Sub



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
TextBox1 to Label4 damorrison Excel Discussion (Misc queries) 5 March 12th 06 04:05 PM
SetFocus on a different sheet in VBA AaronC Excel Discussion (Misc queries) 1 June 9th 05 11:18 PM
Userform1 Border Tom Ogilvy Excel Programming 1 August 13th 03 03:14 PM
Userform1 Border John Wilson Excel Programming 0 August 12th 03 04:08 PM
SetFocus method in VBA Robin S. Excel Programming 2 July 16th 03 10:20 PM


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