Set focus on field not on active page of a multipage
Hello -
I have a VBA form with a multipage control. When the user clicks the SAVE button on the form (it's above the multipage), I need to validate a number of fields on all 4 pages of the multipage control. If a field fails its respective validation, I pop-up a msg box noting the error and then Set Focus on that field. However, if the field that I need to Set Focus on is not on the "active" (i.e. shown) page of the multi-page at the time the user clicks SAVE, I get an error. I have tried using the Multipage1.Value = n to set the correct page before setting focus on the field, but still get an error. Any ideas? Thanks |
Set focus on field not on active page of a multipage
I couldn't reproduce it.
So just for demo purposes to test: Multipage1 Page1 Textbox1 Page2 Textbox2 Page3 Textbox3 so I loop through all the controls and look for a blank textbox. When found, I take the number from the right side of the textbox name, subtract 1 to get the page index (first page is zero) and assign it to the multipage.value property, then set focus. Private Sub CommandButton1_Click() For Each ctl In Me.Controls If TypeOf ctl Is MSForms.TextBox Then If Len(Trim(ctl.Value)) = 0 Then n = Int(Right(ctl.Name, 1)) Me.MultiPage1.Value = n - 1 ctl.SetFocus Exit For End If End If Next End Sub Worked fine for me -- Regards, Tom Ogilvy " wrote: Hello - I have a VBA form with a multipage control. When the user clicks the SAVE button on the form (it's above the multipage), I need to validate a number of fields on all 4 pages of the multipage control. If a field fails its respective validation, I pop-up a msg box noting the error and then Set Focus on that field. However, if the field that I need to Set Focus on is not on the "active" (i.e. shown) page of the multi-page at the time the user clicks SAVE, I get an error. I have tried using the Multipage1.Value = n to set the correct page before setting focus on the field, but still get an error. Any ideas? Thanks |
Set focus on field not on active page of a multipage
If we are working with excel 2003 and the code you suggested are in Private
Sub MultiPage1_Change(), this simply do not work. "Tom Ogilvy" wrote: I couldn't reproduce it. So just for demo purposes to test: Multipage1 Page1 Textbox1 Page2 Textbox2 Page3 Textbox3 so I loop through all the controls and look for a blank textbox. When found, I take the number from the right side of the textbox name, subtract 1 to get the page index (first page is zero) and assign it to the multipage.value property, then set focus. Private Sub CommandButton1_Click() For Each ctl In Me.Controls If TypeOf ctl Is MSForms.TextBox Then If Len(Trim(ctl.Value)) = 0 Then n = Int(Right(ctl.Name, 1)) Me.MultiPage1.Value = n - 1 ctl.SetFocus Exit For End If End If Next End Sub Worked fine for me -- Regards, Tom Ogilvy " wrote: Hello - I have a VBA form with a multipage control. When the user clicks the SAVE button on the form (it's above the multipage), I need to validate a number of fields on all 4 pages of the multipage control. If a field fails its respective validation, I pop-up a msg box noting the error and then Set Focus on that field. However, if the field that I need to Set Focus on is not on the "active" (i.e. shown) page of the multi-page at the time the user clicks SAVE, I get an error. I have tried using the Multipage1.Value = n to set the correct page before setting focus on the field, but still get an error. Any ideas? Thanks |
All times are GMT +1. The time now is 11:47 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com