Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
setfocus in textbox on multipage
Userform1 has a multipage with two pages.
Page1 has 8 textboxes - Text1 through Text8 and 3 comboboxes I would like Text1 to receive focus so data can be entered. My code worked fine on a regular userform but when I changed to a multipage Text1 does not receive focus - I am stumped. Appreciate any help. here is code to load Sub show_myform() Worksheets("Constants").Range("mysounds").Value = 2 UserForm1.ComboBox1.AddItem "Hourly" UserForm1.ComboBox1.AddItem "Milage" UserForm1.ComboBox1.ListIndex = 0 UserForm1.ComboBox2.AddItem "On" UserForm1.ComboBox2.AddItem "Off" UserForm1.ComboBox2.ListIndex = 1 Load UserForm1 On Error Resume Next UserForm1.Show vbModeless 'UserForm1.ComboBox2.ListIndex = 1 With UserForm1.Text1 .SetFocus .SelStart = 0 .SelLength = Len(.Text) Cancel = True End With End Sub -- Martin |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
setfocus in textbox on multipage
Martin,
Set the tab order so that Text1 is first in the tab order. That control gets the focus when the form is shown. The Load UserForm1 line is not necessary as the form loads when you first refer to the form. Also, control settings code should come before the form is shown. Regards, Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware "Martin" wrote in message ... Userform1 has a multipage with two pages. Page1 has 8 textboxes - Text1 through Text8 and 3 comboboxes I would like Text1 to receive focus so data can be entered. My code worked fine on a regular userform but when I changed to a multipage Text1 does not receive focus - I am stumped. Appreciate any help. here is code to load Sub show_myform() Worksheets("Constants").Range("mysounds").Value = 2 UserForm1.ComboBox1.AddItem "Hourly" UserForm1.ComboBox1.AddItem "Milage" UserForm1.ComboBox1.ListIndex = 0 UserForm1.ComboBox2.AddItem "On" UserForm1.ComboBox2.AddItem "Off" UserForm1.ComboBox2.ListIndex = 1 Load UserForm1 On Error Resume Next UserForm1.Show vbModeless 'UserForm1.ComboBox2.ListIndex = 1 With UserForm1.Text1 .SetFocus .SelStart = 0 .SelLength = Len(.Text) Cancel = True End With End Sub -- Martin |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
setfocus in textbox on multipage
Jim,
Thank you for your comments. Text1 has a tabindex of 0. I've made the other changes uou indicated but Text1 still does not receive the focus. When I just had the items on a userform Text1 would receive focus. The problem developed when I went to MultiPage. Any thoughts? Martin -- Martin "Jim Cone" wrote: Martin, Set the tab order so that Text1 is first in the tab order. That control gets the focus when the form is shown. The Load UserForm1 line is not necessary as the form loads when you first refer to the form. Also, control settings code should come before the form is shown. Regards, Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware "Martin" wrote in message ... Userform1 has a multipage with two pages. Page1 has 8 textboxes - Text1 through Text8 and 3 comboboxes I would like Text1 to receive focus so data can be entered. My code worked fine on a regular userform but when I changed to a multipage Text1 does not receive focus - I am stumped. Appreciate any help. here is code to load Sub show_myform() Worksheets("Constants").Range("mysounds").Value = 2 UserForm1.ComboBox1.AddItem "Hourly" UserForm1.ComboBox1.AddItem "Milage" UserForm1.ComboBox1.ListIndex = 0 UserForm1.ComboBox2.AddItem "On" UserForm1.ComboBox2.AddItem "Off" UserForm1.ComboBox2.ListIndex = 1 Load UserForm1 On Error Resume Next UserForm1.Show vbModeless 'UserForm1.ComboBox2.ListIndex = 1 With UserForm1.Text1 .SetFocus .SelStart = 0 .SelLength = Len(.Text) Cancel = True End With End Sub -- Martin |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
setfocus in textbox on multipage
Martin,
If the textbox is on one of the pages (not directly on the userform) then code something like this could be used... Private Sub UserForm_Activate() With Me.MultiPage1 'Make the second page active .Value = 1 .Pages(1).TextBox4.SetFocus End With End Sub '---------------------------- Jim Cone "Martin" wrote in message Jim, Thank you for your comments. Text1 has a tabindex of 0. I've made the other changes uou indicated but Text1 still does not receive the focus. When I just had the items on a userform Text1 would receive focus. The problem developed when I went to MultiPage. Any thoughts? Martin "Jim Cone" wrote: Martin, Set the tab order so that Text1 is first in the tab order. That control gets the focus when the form is shown. The Load UserForm1 line is not necessary as the form loads when you first refer to the form. Also, control settings code should come before the form is shown. Regards, Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware "Martin" wrote in message ... Userform1 has a multipage with two pages. Page1 has 8 textboxes - Text1 through Text8 and 3 comboboxes I would like Text1 to receive focus so data can be entered. My code worked fine on a regular userform but when I changed to a multipage Text1 does not receive focus - I am stumped. Appreciate any help. here is code to load Sub show_myform() Worksheets("Constants").Range("mysounds").Value = 2 UserForm1.ComboBox1.AddItem "Hourly" UserForm1.ComboBox1.AddItem "Milage" UserForm1.ComboBox1.ListIndex = 0 UserForm1.ComboBox2.AddItem "On" UserForm1.ComboBox2.AddItem "Off" UserForm1.ComboBox2.ListIndex = 1 Load UserForm1 On Error Resume Next UserForm1.Show vbModeless 'UserForm1.ComboBox2.ListIndex = 1 With UserForm1.Text1 .SetFocus .SelStart = 0 .SelLength = Len(.Text) Cancel = True End With End Sub -- Martin |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
setfocus in textbox on multipage
Jim,
Thanks again. I got an invalid use of ME error & modified code. The textbox is on the firstpage of a 2 page muultipage on top of a userform. With UserForm1.MultiPage1 'Make the second page active ..Value = 0 ..Pages(0).Text1.SetFocus End With I'm guessing that 0 is the index of the first page as I had error 438 (obj does not supp..)when .value was 1 and error 2110 with .pages(1) I dont get errors with code shown but dont get focus in textbox either. What is weird is when I use Tab key - the focus goes to textbox2 which is the next tab order. Martin -- Martin "Jim Cone" wrote: Martin, If the textbox is on one of the pages (not directly on the userform) then code something like this could be used... Private Sub UserForm_Activate() With Me.MultiPage1 'Make the second page active .Value = 1 .Pages(1).TextBox4.SetFocus End With End Sub '---------------------------- Jim Cone "Martin" wrote in message Jim, Thank you for your comments. Text1 has a tabindex of 0. I've made the other changes uou indicated but Text1 still does not receive the focus. When I just had the items on a userform Text1 would receive focus. The problem developed when I went to MultiPage. Any thoughts? Martin "Jim Cone" wrote: Martin, Set the tab order so that Text1 is first in the tab order. That control gets the focus when the form is shown. The Load UserForm1 line is not necessary as the form loads when you first refer to the form. Also, control settings code should come before the form is shown. Regards, Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware "Martin" wrote in message ... Userform1 has a multipage with two pages. Page1 has 8 textboxes - Text1 through Text8 and 3 comboboxes I would like Text1 to receive focus so data can be entered. My code worked fine on a regular userform but when I changed to a multipage Text1 does not receive focus - I am stumped. Appreciate any help. here is code to load Sub show_myform() Worksheets("Constants").Range("mysounds").Value = 2 UserForm1.ComboBox1.AddItem "Hourly" UserForm1.ComboBox1.AddItem "Milage" UserForm1.ComboBox1.ListIndex = 0 UserForm1.ComboBox2.AddItem "On" UserForm1.ComboBox2.AddItem "Off" UserForm1.ComboBox2.ListIndex = 1 Load UserForm1 On Error Resume Next UserForm1.Show vbModeless 'UserForm1.ComboBox2.ListIndex = 1 With UserForm1.Text1 .SetFocus .SelStart = 0 .SelLength = Len(.Text) Cancel = True End With End Sub -- Martin |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
setfocus in textbox on multipage
Martin,
Code to control the initial display and configuration of a userform can usually go in three places... The general module calling the form The Initialize event of the form The Activate event of the form The initialize event occurs when the form is loaded. The activate event occurs each time the form is shown. The "Me" word refers to the form itself and can only be used in the form's code module. A userform and each page of a multipage control have their own independent tab orders. Hope some of the above can help you work out the problem. Jim Cone http://www.realezsites.com/bus/primitivesoftware "Martin" wrote in message ... Jim, Thanks again. I got an invalid use of ME error & modified code. The textbox is on the firstpage of a 2 page multipage on top of a userform. With UserForm1.MultiPage1 'Make the second page active ..Value = 0 ..Pages(0).Text1.SetFocus End With I'm guessing that 0 is the index of the first page as I had error 438 (obj does not supp..)when .value was 1 and error 2110 with .pages(1) I dont get errors with code shown but dont get focus in textbox either. What is weird is when I use Tab key - the focus goes to textbox2 which is the next tab order. Martin -- Martin "Jim Cone" wrote: Martin, If the textbox is on one of the pages (not directly on the userform) then code something like this could be used... Private Sub UserForm_Activate() With Me.MultiPage1 'Make the second page active .Value = 1 .Pages(1).TextBox4.SetFocus End With End Sub '---------------------------- Jim Cone "Martin" wrote in message Jim, Thank you for your comments. Text1 has a tabindex of 0. I've made the other changes uou indicated but Text1 still does not receive the focus. When I just had the items on a userform Text1 would receive focus. The problem developed when I went to MultiPage. Any thoughts? Martin "Jim Cone" wrote: Martin, Set the tab order so that Text1 is first in the tab order. That control gets the focus when the form is shown. The Load UserForm1 line is not necessary as the form loads when you first refer to the form. Also, control settings code should come before the form is shown. Regards, Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware "Martin" wrote in message ... Userform1 has a multipage with two pages. Page1 has 8 textboxes - Text1 through Text8 and 3 comboboxes I would like Text1 to receive focus so data can be entered. My code worked fine on a regular userform but when I changed to a multipage Text1 does not receive focus - I am stumped. Appreciate any help. here is code to load Sub show_myform() Worksheets("Constants").Range("mysounds").Value = 2 UserForm1.ComboBox1.AddItem "Hourly" UserForm1.ComboBox1.AddItem "Milage" UserForm1.ComboBox1.ListIndex = 0 UserForm1.ComboBox2.AddItem "On" UserForm1.ComboBox2.AddItem "Off" UserForm1.ComboBox2.ListIndex = 1 Load UserForm1 On Error Resume Next UserForm1.Show vbModeless 'UserForm1.ComboBox2.ListIndex = 1 With UserForm1.Text1 .SetFocus .SelStart = 0 .SelLength = Len(.Text) Cancel = True End With End Sub -- Martin |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
setfocus on multipage tab form gives error message | Excel Programming | |||
SetFocus to first textbox on userform upon Userform1.Show | Excel Programming | |||
TextBox SetFocus Problem | Excel Programming | |||
TextBox.SetFocus | Excel Programming |