View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
sebastienm sebastienm is offline
external usenet poster
 
Posts: 694
Default Set Focus Problem for textbox control on multipage control

Hi Sue,

I don't have 2003 but i guess part of what happens is:

In the first Change SUb, you set the Value property of the multipage which triggers the Change sub a second time while it has not left the first one yet.

In 2003, it goes back to the 1st tab (for some reason i don't know) before it reaches the SetFocus from a control on another tab (not the active), therefore an error because the tab should be activated before doing a SetFocus.

If, in a basic form containing 1 multipage only, you put the code:
'-------------------------------
Private i As Integer
Private Sub MultiPage1_Change()
i = i + 1
MsgBox i
MultiPage1.Value = IIf(MultiPage1.Value = 0, 1, 0)
End Sub
'--------------------------------
Once you click a tab, it doesn't stop : the next tab is select , then the first, then... (pressCTRL+Break) to stop the code

I would try to *disable* the event handler _Change when you programatically change the Value of the Multipage so that it is not triggered an extra time:
1. At the top of the form, add a variable
Private progMode as boolean 'True if Value changed programaticaly
(when the form is shown, this value is autmotically set to false
2. In the Change event, before settingadd
Private Sub MultiPage1_Change()
if progMode then exit sub 'Not processed if change programmaticaly '...
' your code here
'...
End Sub
3.And finally, anywhere you set the Multipage.Value property programmatically, wrap it with:
progMode = True
MultiPage1.Value= ...
progMode = False

I hope this helps,
--
Regards,
Sébastien