Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

The following code fails at line 2 with Object vaiable not set and I cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a multipage hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay" Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default ActiveControl again

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay" Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set and I cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a multipage hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay" Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay" Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set and I cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a multipage hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay" Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of the frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay" Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set and I cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a multipage hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay" Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ActiveControl again

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of the

frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay"

Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set and I

cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a multipage

hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay"

Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

To get the control with focus when tabbing through the form. The problem is
how deep to go with activecontrol. The optionbuttons are within a frame on a
multipage.

So far I have:
Me.ActiveControl.Name returns "MultiPage1"
Me.MultiPage1.SelectedItem.Name returns "Page1"
Me.MultiPage1.SelectedItem.ActiveControl.Name returns "fraOneDayTwoDay"

but I cannot get to the controls within the frame fraOneDayTwoDay which are
named as optOneDay and optTwoDay.

Geoff


"Tom Ogilvy" wrote:

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of the

frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay"

Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set and I

cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a multipage

hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name = "fraOneDayTwoDay"

Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ActiveControl again

Set up a Multipage with 2 pages. Each page had a Frame. Each frame had two
option buttons.

All code is in the userform. So just keep adding on ActionControl as shown
in the second msgbox.

Sub WhichOptionButton()
Dim c As MultiPage
Dim c1 As Page
Dim c2 As Frame
Set c = Me.ActiveControl
If TypeOf c Is MSForms.MultiPage Then
Set c1 = c.SelectedItem
If TypeOf c1 Is MSForms.Page Then
Set c2 = c1.ActiveControl
If TypeOf c2 Is MSForms.Frame Then
Set c3 = c2.ActiveControl
MsgBox c.Name & vbNewLine & _
" " & c1.Name & vbNewLine & _
" " & c2.Name & vbNewLine & _
" " & c3.Name
MsgBox Me.ActiveControl.SelectedItem _
.ActiveControl.ActiveControl.Name
End If
End If
End If

End Sub


Private Sub OptionButton1_Click()
WhichOptionButton
End Sub

Private Sub OptionButton2_Click()
WhichOptionButton
End Sub

Private Sub optOneDay_Click()
WhichOptionButton
End Sub

Private Sub opttwoDay_Click()
WhichOptionButton
End Sub

--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
To get the control with focus when tabbing through the form. The problem

is
how deep to go with activecontrol. The optionbuttons are within a frame

on a
multipage.

So far I have:
Me.ActiveControl.Name returns "MultiPage1"
Me.MultiPage1.SelectedItem.Name returns "Page1"
Me.MultiPage1.SelectedItem.ActiveControl.Name returns "fraOneDayTwoDay"

but I cannot get to the controls within the frame fraOneDayTwoDay which

are
named as optOneDay and optTwoDay.

Geoff


"Tom Ogilvy" wrote:

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of

the
frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name =

"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set

and I
cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a

multipage
hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name =

"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

Thanks, I have tried the code and it works fine in your example. I'm away
now at nearly 03:00 and I shall implement the solution after some shuteye.
The process is clearly dependedent on the proper object setting and I thank
you again for the very graphic demo.

Geoff

"Tom Ogilvy" wrote:

Set up a Multipage with 2 pages. Each page had a Frame. Each frame had two
option buttons.

All code is in the userform. So just keep adding on ActionControl as shown
in the second msgbox.

Sub WhichOptionButton()
Dim c As MultiPage
Dim c1 As Page
Dim c2 As Frame
Set c = Me.ActiveControl
If TypeOf c Is MSForms.MultiPage Then
Set c1 = c.SelectedItem
If TypeOf c1 Is MSForms.Page Then
Set c2 = c1.ActiveControl
If TypeOf c2 Is MSForms.Frame Then
Set c3 = c2.ActiveControl
MsgBox c.Name & vbNewLine & _
" " & c1.Name & vbNewLine & _
" " & c2.Name & vbNewLine & _
" " & c3.Name
MsgBox Me.ActiveControl.SelectedItem _
.ActiveControl.ActiveControl.Name
End If
End If
End If

End Sub


Private Sub OptionButton1_Click()
WhichOptionButton
End Sub

Private Sub OptionButton2_Click()
WhichOptionButton
End Sub

Private Sub optOneDay_Click()
WhichOptionButton
End Sub

Private Sub opttwoDay_Click()
WhichOptionButton
End Sub

--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
To get the control with focus when tabbing through the form. The problem

is
how deep to go with activecontrol. The optionbuttons are within a frame

on a
multipage.

So far I have:
Me.ActiveControl.Name returns "MultiPage1"
Me.MultiPage1.SelectedItem.Name returns "Page1"
Me.MultiPage1.SelectedItem.ActiveControl.Name returns "fraOneDayTwoDay"

but I cannot get to the controls within the frame fraOneDayTwoDay which

are
named as optOneDay and optTwoDay.

Geoff


"Tom Ogilvy" wrote:

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of

the
frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name =

"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set

and I
cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a

multipage
hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name =

"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

Uh-uh - after further testing there is something still not quite right.
I amended the form by recreating Page1 and adding 2 textboxes followed by a
frame containing 2 optbuttons and 2 labels followed by another 2 textboxes to
create a scenario more like the real form.

I amended the code as below to tab rather than click. I also made Page1
Cycle fmCycleCurrentForm.

The action works fine as you tab from txt1 thru to txt4 and tab in a
continuous loop
but then if you start to back tab from txt4 it will miss out on optbutton 2
label until the back tabbing has completed a cycle of all controls. If you
continue to back tab all is well.
But then if you start tabbing forward again it will miss out on optbutton 1
label. There appears to be some counter which is not setting correctly until
a cycle has been completed.

Is there something to remedy this?

Geoff


Sub WhichOptionButton()
If Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton1" Then
Label1.Visible = True
ElseIf Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton2" Then
Label2.Visible = True
End If
End Sub

Private Sub OptionButton1_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton2_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
End Sub

Private Sub OptionButton2_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label2.Visible = False
End Sub

Private Sub Frame1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
Label2.Visible = False
End Sub

"Geoff" wrote:

Thanks, I have tried the code and it works fine in your example. I'm away
now at nearly 03:00 and I shall implement the solution after some shuteye.
The process is clearly dependedent on the proper object setting and I thank
you again for the very graphic demo.

Geoff

"Tom Ogilvy" wrote:

Set up a Multipage with 2 pages. Each page had a Frame. Each frame had two
option buttons.

All code is in the userform. So just keep adding on ActionControl as shown
in the second msgbox.

Sub WhichOptionButton()
Dim c As MultiPage
Dim c1 As Page
Dim c2 As Frame
Set c = Me.ActiveControl
If TypeOf c Is MSForms.MultiPage Then
Set c1 = c.SelectedItem
If TypeOf c1 Is MSForms.Page Then
Set c2 = c1.ActiveControl
If TypeOf c2 Is MSForms.Frame Then
Set c3 = c2.ActiveControl
MsgBox c.Name & vbNewLine & _
" " & c1.Name & vbNewLine & _
" " & c2.Name & vbNewLine & _
" " & c3.Name
MsgBox Me.ActiveControl.SelectedItem _
.ActiveControl.ActiveControl.Name
End If
End If
End If

End Sub


Private Sub OptionButton1_Click()
WhichOptionButton
End Sub

Private Sub OptionButton2_Click()
WhichOptionButton
End Sub

Private Sub optOneDay_Click()
WhichOptionButton
End Sub

Private Sub opttwoDay_Click()
WhichOptionButton
End Sub

--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
To get the control with focus when tabbing through the form. The problem

is
how deep to go with activecontrol. The optionbuttons are within a frame

on a
multipage.

So far I have:
Me.ActiveControl.Name returns "MultiPage1"
Me.MultiPage1.SelectedItem.Name returns "Page1"
Me.MultiPage1.SelectedItem.ActiveControl.Name returns "fraOneDayTwoDay"

but I cannot get to the controls within the frame fraOneDayTwoDay which

are
named as optOneDay and optTwoDay.

Geoff


"Tom Ogilvy" wrote:

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of

the
frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name =

"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set

and I
cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a

multipage
hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name =

"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff






  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

On further testing I found that both optbutton enter events do not fire if
tabbing is reversed outside the frame i.e.

If you tab from txt2 into fra1 then, opt1 enter is fired then opt2 enter is
fired then fra1 exit is fired before txt3 receives focus. Fine.
But if you backtab from txt3 to opt2 the opt2 enter event is NOT fired -
though the control clearly receives focus - if you continue to backtab in the
frame, opt1 enter is fired then fra1 exit is fired before txt2 receives focus.
This time if you tab forward from txt2 then opt1 enter is not fired though
the control receives focus. And so on.
As before, if a full cycle thru all controls forward or back is executed
then all events are fired as expected.

To refine the process I introduced a fra1 enter event - no statements - to
see what happened. This fired as expected thru all tabbing and back tabbing.

It seems to me therefore that recognition of optbutton activecontrol
requires some form of code in the frame enter event which is where the error
91 "object variable or with block variable not set" began originally.

Any further comments would be much appreciated.

Geoff


"Geoff" wrote:

Uh-uh - after further testing there is something still not quite right.
I amended the form by recreating Page1 and adding 2 textboxes followed by a
frame containing 2 optbuttons and 2 labels followed by another 2 textboxes to
create a scenario more like the real form.

I amended the code as below to tab rather than click. I also made Page1
Cycle fmCycleCurrentForm.

The action works fine as you tab from txt1 thru to txt4 and tab in a
continuous loop
but then if you start to back tab from txt4 it will miss out on optbutton 2
label until the back tabbing has completed a cycle of all controls. If you
continue to back tab all is well.
But then if you start tabbing forward again it will miss out on optbutton 1
label. There appears to be some counter which is not setting correctly until
a cycle has been completed.

Is there something to remedy this?

Geoff


Sub WhichOptionButton()
If Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton1" Then
Label1.Visible = True
ElseIf Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton2" Then
Label2.Visible = True
End If
End Sub

Private Sub OptionButton1_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton2_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
End Sub

Private Sub OptionButton2_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label2.Visible = False
End Sub

Private Sub Frame1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
Label2.Visible = False
End Sub

"Geoff" wrote:

Thanks, I have tried the code and it works fine in your example. I'm away
now at nearly 03:00 and I shall implement the solution after some shuteye.
The process is clearly dependedent on the proper object setting and I thank
you again for the very graphic demo.

Geoff

"Tom Ogilvy" wrote:

Set up a Multipage with 2 pages. Each page had a Frame. Each frame had two
option buttons.

All code is in the userform. So just keep adding on ActionControl as shown
in the second msgbox.

Sub WhichOptionButton()
Dim c As MultiPage
Dim c1 As Page
Dim c2 As Frame
Set c = Me.ActiveControl
If TypeOf c Is MSForms.MultiPage Then
Set c1 = c.SelectedItem
If TypeOf c1 Is MSForms.Page Then
Set c2 = c1.ActiveControl
If TypeOf c2 Is MSForms.Frame Then
Set c3 = c2.ActiveControl
MsgBox c.Name & vbNewLine & _
" " & c1.Name & vbNewLine & _
" " & c2.Name & vbNewLine & _
" " & c3.Name
MsgBox Me.ActiveControl.SelectedItem _
.ActiveControl.ActiveControl.Name
End If
End If
End If

End Sub


Private Sub OptionButton1_Click()
WhichOptionButton
End Sub

Private Sub OptionButton2_Click()
WhichOptionButton
End Sub

Private Sub optOneDay_Click()
WhichOptionButton
End Sub

Private Sub opttwoDay_Click()
WhichOptionButton
End Sub

--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
To get the control with focus when tabbing through the form. The problem
is
how deep to go with activecontrol. The optionbuttons are within a frame
on a
multipage.

So far I have:
Me.ActiveControl.Name returns "MultiPage1"
Me.MultiPage1.SelectedItem.Name returns "Page1"
Me.MultiPage1.SelectedItem.ActiveControl.Name returns "fraOneDayTwoDay"

but I cannot get to the controls within the frame fraOneDayTwoDay which
are
named as optOneDay and optTwoDay.

Geoff


"Tom Ogilvy" wrote:

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of
the
frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name =
"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set
and I
cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a
multipage
hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name =
"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff








  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default ActiveControl again

I don't doubt that what you say is true. I know if you have textboxes in a
frame, and tab through the textboxes, the exit event of the last textbox
doesn't fire, the frame exit event fires as I recall.

I think you are in the realm of workarounds (not knowing what you are doing).

--
Regards,
Tom Ogilvy


"Geoff" wrote:

On further testing I found that both optbutton enter events do not fire if
tabbing is reversed outside the frame i.e.

If you tab from txt2 into fra1 then, opt1 enter is fired then opt2 enter is
fired then fra1 exit is fired before txt3 receives focus. Fine.
But if you backtab from txt3 to opt2 the opt2 enter event is NOT fired -
though the control clearly receives focus - if you continue to backtab in the
frame, opt1 enter is fired then fra1 exit is fired before txt2 receives focus.
This time if you tab forward from txt2 then opt1 enter is not fired though
the control receives focus. And so on.
As before, if a full cycle thru all controls forward or back is executed
then all events are fired as expected.

To refine the process I introduced a fra1 enter event - no statements - to
see what happened. This fired as expected thru all tabbing and back tabbing.

It seems to me therefore that recognition of optbutton activecontrol
requires some form of code in the frame enter event which is where the error
91 "object variable or with block variable not set" began originally.

Any further comments would be much appreciated.

Geoff


"Geoff" wrote:

Uh-uh - after further testing there is something still not quite right.
I amended the form by recreating Page1 and adding 2 textboxes followed by a
frame containing 2 optbuttons and 2 labels followed by another 2 textboxes to
create a scenario more like the real form.

I amended the code as below to tab rather than click. I also made Page1
Cycle fmCycleCurrentForm.

The action works fine as you tab from txt1 thru to txt4 and tab in a
continuous loop
but then if you start to back tab from txt4 it will miss out on optbutton 2
label until the back tabbing has completed a cycle of all controls. If you
continue to back tab all is well.
But then if you start tabbing forward again it will miss out on optbutton 1
label. There appears to be some counter which is not setting correctly until
a cycle has been completed.

Is there something to remedy this?

Geoff


Sub WhichOptionButton()
If Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton1" Then
Label1.Visible = True
ElseIf Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton2" Then
Label2.Visible = True
End If
End Sub

Private Sub OptionButton1_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton2_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
End Sub

Private Sub OptionButton2_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label2.Visible = False
End Sub

Private Sub Frame1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
Label2.Visible = False
End Sub

"Geoff" wrote:

Thanks, I have tried the code and it works fine in your example. I'm away
now at nearly 03:00 and I shall implement the solution after some shuteye.
The process is clearly dependedent on the proper object setting and I thank
you again for the very graphic demo.

Geoff

"Tom Ogilvy" wrote:

Set up a Multipage with 2 pages. Each page had a Frame. Each frame had two
option buttons.

All code is in the userform. So just keep adding on ActionControl as shown
in the second msgbox.

Sub WhichOptionButton()
Dim c As MultiPage
Dim c1 As Page
Dim c2 As Frame
Set c = Me.ActiveControl
If TypeOf c Is MSForms.MultiPage Then
Set c1 = c.SelectedItem
If TypeOf c1 Is MSForms.Page Then
Set c2 = c1.ActiveControl
If TypeOf c2 Is MSForms.Frame Then
Set c3 = c2.ActiveControl
MsgBox c.Name & vbNewLine & _
" " & c1.Name & vbNewLine & _
" " & c2.Name & vbNewLine & _
" " & c3.Name
MsgBox Me.ActiveControl.SelectedItem _
.ActiveControl.ActiveControl.Name
End If
End If
End If

End Sub


Private Sub OptionButton1_Click()
WhichOptionButton
End Sub

Private Sub OptionButton2_Click()
WhichOptionButton
End Sub

Private Sub optOneDay_Click()
WhichOptionButton
End Sub

Private Sub opttwoDay_Click()
WhichOptionButton
End Sub

--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
To get the control with focus when tabbing through the form. The problem
is
how deep to go with activecontrol. The optionbuttons are within a frame
on a
multipage.

So far I have:
Me.ActiveControl.Name returns "MultiPage1"
Me.MultiPage1.SelectedItem.Name returns "Page1"
Me.MultiPage1.SelectedItem.ActiveControl.Name returns "fraOneDayTwoDay"

but I cannot get to the controls within the frame fraOneDayTwoDay which
are
named as optOneDay and optTwoDay.

Geoff


"Tom Ogilvy" wrote:

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of
the
frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name =
"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set
and I
cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a
multipage
hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name =
"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff






  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

Ok. From the threads I've seen for a couple of years or more I know it's
very rare you cannot find a solution. Thank you very much for the effort you
have made, it is appreciated. I thought it was there until by chance I did a
backtab staight from the txtbox after the frame. Maybe this and probably
other things are what has been improved with VB6 and dot net but then there
are still a whole shedful of people out there still happy using VBA.
Thanks again - if I do find a workaround I'll put that in a thread for
others to share.

To answer the query what was I doing? The desire for a better visual cue on
optbuttons and chkboxes than the marquee surrounding the contol's own label
and constraints on the label position decided me to associate separate labels
with the controls instead. This stategy works great until you have to
consider users wanting to tab and use accelerator keys, then the recognition
of the active control within frames becomes necessary. The irony is after
nearly finishing this long project I was reminded using your example that the
marquee, of course, follows the activecontrol wherever the focus goes. I
wonder how they do that???? <vbg

Geoff

"Tom Ogilvy" wrote:

I don't doubt that what you say is true. I know if you have textboxes in a
frame, and tab through the textboxes, the exit event of the last textbox
doesn't fire, the frame exit event fires as I recall.

I think you are in the realm of workarounds (not knowing what you are doing).

--
Regards,
Tom Ogilvy


"Geoff" wrote:

On further testing I found that both optbutton enter events do not fire if
tabbing is reversed outside the frame i.e.

If you tab from txt2 into fra1 then, opt1 enter is fired then opt2 enter is
fired then fra1 exit is fired before txt3 receives focus. Fine.
But if you backtab from txt3 to opt2 the opt2 enter event is NOT fired -
though the control clearly receives focus - if you continue to backtab in the
frame, opt1 enter is fired then fra1 exit is fired before txt2 receives focus.
This time if you tab forward from txt2 then opt1 enter is not fired though
the control receives focus. And so on.
As before, if a full cycle thru all controls forward or back is executed
then all events are fired as expected.

To refine the process I introduced a fra1 enter event - no statements - to
see what happened. This fired as expected thru all tabbing and back tabbing.

It seems to me therefore that recognition of optbutton activecontrol
requires some form of code in the frame enter event which is where the error
91 "object variable or with block variable not set" began originally.

Any further comments would be much appreciated.

Geoff


"Geoff" wrote:

Uh-uh - after further testing there is something still not quite right.
I amended the form by recreating Page1 and adding 2 textboxes followed by a
frame containing 2 optbuttons and 2 labels followed by another 2 textboxes to
create a scenario more like the real form.

I amended the code as below to tab rather than click. I also made Page1
Cycle fmCycleCurrentForm.

The action works fine as you tab from txt1 thru to txt4 and tab in a
continuous loop
but then if you start to back tab from txt4 it will miss out on optbutton 2
label until the back tabbing has completed a cycle of all controls. If you
continue to back tab all is well.
But then if you start tabbing forward again it will miss out on optbutton 1
label. There appears to be some counter which is not setting correctly until
a cycle has been completed.

Is there something to remedy this?

Geoff


Sub WhichOptionButton()
If Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton1" Then
Label1.Visible = True
ElseIf Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton2" Then
Label2.Visible = True
End If
End Sub

Private Sub OptionButton1_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton2_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
End Sub

Private Sub OptionButton2_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label2.Visible = False
End Sub

Private Sub Frame1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
Label2.Visible = False
End Sub

"Geoff" wrote:

Thanks, I have tried the code and it works fine in your example. I'm away
now at nearly 03:00 and I shall implement the solution after some shuteye.
The process is clearly dependedent on the proper object setting and I thank
you again for the very graphic demo.

Geoff

"Tom Ogilvy" wrote:

Set up a Multipage with 2 pages. Each page had a Frame. Each frame had two
option buttons.

All code is in the userform. So just keep adding on ActionControl as shown
in the second msgbox.

Sub WhichOptionButton()
Dim c As MultiPage
Dim c1 As Page
Dim c2 As Frame
Set c = Me.ActiveControl
If TypeOf c Is MSForms.MultiPage Then
Set c1 = c.SelectedItem
If TypeOf c1 Is MSForms.Page Then
Set c2 = c1.ActiveControl
If TypeOf c2 Is MSForms.Frame Then
Set c3 = c2.ActiveControl
MsgBox c.Name & vbNewLine & _
" " & c1.Name & vbNewLine & _
" " & c2.Name & vbNewLine & _
" " & c3.Name
MsgBox Me.ActiveControl.SelectedItem _
.ActiveControl.ActiveControl.Name
End If
End If
End If

End Sub


Private Sub OptionButton1_Click()
WhichOptionButton
End Sub

Private Sub OptionButton2_Click()
WhichOptionButton
End Sub

Private Sub optOneDay_Click()
WhichOptionButton
End Sub

Private Sub opttwoDay_Click()
WhichOptionButton
End Sub

--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
To get the control with focus when tabbing through the form. The problem
is
how deep to go with activecontrol. The optionbuttons are within a frame
on a
multipage.

So far I have:
Me.ActiveControl.Name returns "MultiPage1"
Me.MultiPage1.SelectedItem.Name returns "Page1"
Me.MultiPage1.SelectedItem.ActiveControl.Name returns "fraOneDayTwoDay"

but I cannot get to the controls within the frame fraOneDayTwoDay which
are
named as optOneDay and optTwoDay.

Geoff


"Tom Ogilvy" wrote:

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of
the
frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name =
"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set
and I
cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a
multipage
hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name =
"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff






  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default ActiveControl again

I've decided. There are only 3 frames on page1 I have to consider. For
other reasons I have moved controls out of their original frames on page2
already. It was hassle to recode but I think the advantages to be gained by
seperate labelling are too much to lose and I shall do the same on page1. I
will keep the frames as containers only to hold focus for example but the
controls I will put outside and the problem of identifying the asctivecontrol
of optbuttons and chkboxes on a page itself is easy. Whist not resolving the
issue it is a workaround I can live with.

Again thanks.

Geoff

"Geoff" wrote:

Ok. From the threads I've seen for a couple of years or more I know it's
very rare you cannot find a solution. Thank you very much for the effort you
have made, it is appreciated. I thought it was there until by chance I did a
backtab staight from the txtbox after the frame. Maybe this and probably
other things are what has been improved with VB6 and dot net but then there
are still a whole shedful of people out there still happy using VBA.
Thanks again - if I do find a workaround I'll put that in a thread for
others to share.

To answer the query what was I doing? The desire for a better visual cue on
optbuttons and chkboxes than the marquee surrounding the contol's own label
and constraints on the label position decided me to associate separate labels
with the controls instead. This stategy works great until you have to
consider users wanting to tab and use accelerator keys, then the recognition
of the active control within frames becomes necessary. The irony is after
nearly finishing this long project I was reminded using your example that the
marquee, of course, follows the activecontrol wherever the focus goes. I
wonder how they do that???? <vbg

Geoff

"Tom Ogilvy" wrote:

I don't doubt that what you say is true. I know if you have textboxes in a
frame, and tab through the textboxes, the exit event of the last textbox
doesn't fire, the frame exit event fires as I recall.

I think you are in the realm of workarounds (not knowing what you are doing).

--
Regards,
Tom Ogilvy


"Geoff" wrote:

On further testing I found that both optbutton enter events do not fire if
tabbing is reversed outside the frame i.e.

If you tab from txt2 into fra1 then, opt1 enter is fired then opt2 enter is
fired then fra1 exit is fired before txt3 receives focus. Fine.
But if you backtab from txt3 to opt2 the opt2 enter event is NOT fired -
though the control clearly receives focus - if you continue to backtab in the
frame, opt1 enter is fired then fra1 exit is fired before txt2 receives focus.
This time if you tab forward from txt2 then opt1 enter is not fired though
the control receives focus. And so on.
As before, if a full cycle thru all controls forward or back is executed
then all events are fired as expected.

To refine the process I introduced a fra1 enter event - no statements - to
see what happened. This fired as expected thru all tabbing and back tabbing.

It seems to me therefore that recognition of optbutton activecontrol
requires some form of code in the frame enter event which is where the error
91 "object variable or with block variable not set" began originally.

Any further comments would be much appreciated.

Geoff


"Geoff" wrote:

Uh-uh - after further testing there is something still not quite right.
I amended the form by recreating Page1 and adding 2 textboxes followed by a
frame containing 2 optbuttons and 2 labels followed by another 2 textboxes to
create a scenario more like the real form.

I amended the code as below to tab rather than click. I also made Page1
Cycle fmCycleCurrentForm.

The action works fine as you tab from txt1 thru to txt4 and tab in a
continuous loop
but then if you start to back tab from txt4 it will miss out on optbutton 2
label until the back tabbing has completed a cycle of all controls. If you
continue to back tab all is well.
But then if you start tabbing forward again it will miss out on optbutton 1
label. There appears to be some counter which is not setting correctly until
a cycle has been completed.

Is there something to remedy this?

Geoff


Sub WhichOptionButton()
If Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton1" Then
Label1.Visible = True
ElseIf Me.ActiveControl.SelectedItem.ActiveControl.Active Control.Name =
"OptionButton2" Then
Label2.Visible = True
End If
End Sub

Private Sub OptionButton1_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton2_Enter()
WhichOptionButton
End Sub

Private Sub OptionButton1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
End Sub

Private Sub OptionButton2_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label2.Visible = False
End Sub

Private Sub Frame1_Exit(ByVal Cancel As msforms.ReturnBoolean)
Label1.Visible = False
Label2.Visible = False
End Sub

"Geoff" wrote:

Thanks, I have tried the code and it works fine in your example. I'm away
now at nearly 03:00 and I shall implement the solution after some shuteye.
The process is clearly dependedent on the proper object setting and I thank
you again for the very graphic demo.

Geoff

"Tom Ogilvy" wrote:

Set up a Multipage with 2 pages. Each page had a Frame. Each frame had two
option buttons.

All code is in the userform. So just keep adding on ActionControl as shown
in the second msgbox.

Sub WhichOptionButton()
Dim c As MultiPage
Dim c1 As Page
Dim c2 As Frame
Set c = Me.ActiveControl
If TypeOf c Is MSForms.MultiPage Then
Set c1 = c.SelectedItem
If TypeOf c1 Is MSForms.Page Then
Set c2 = c1.ActiveControl
If TypeOf c2 Is MSForms.Frame Then
Set c3 = c2.ActiveControl
MsgBox c.Name & vbNewLine & _
" " & c1.Name & vbNewLine & _
" " & c2.Name & vbNewLine & _
" " & c3.Name
MsgBox Me.ActiveControl.SelectedItem _
.ActiveControl.ActiveControl.Name
End If
End If
End If

End Sub


Private Sub OptionButton1_Click()
WhichOptionButton
End Sub

Private Sub OptionButton2_Click()
WhichOptionButton
End Sub

Private Sub optOneDay_Click()
WhichOptionButton
End Sub

Private Sub opttwoDay_Click()
WhichOptionButton
End Sub

--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
To get the control with focus when tabbing through the form. The problem
is
how deep to go with activecontrol. The optionbuttons are within a frame
on a
multipage.

So far I have:
Me.ActiveControl.Name returns "MultiPage1"
Me.MultiPage1.SelectedItem.Name returns "Page1"
Me.MultiPage1.SelectedItem.ActiveControl.Name returns "fraOneDayTwoDay"

but I cannot get to the controls within the frame fraOneDayTwoDay which
are
named as optOneDay and optTwoDay.

Geoff


"Tom Ogilvy" wrote:

What are you actually trying to determine/do?

--
Regards,
Tom Ogilvy

"Geoff" wrote in message
...
Tom
I thought at first that was the solution but by coincidence it was
referencing the same tabindexc of the multipage not the tabindex of
the
frame
control . So i'm still stuck on this.

Geoff

"Geoff" wrote:

Thank you.

Geoff

"Tom Ogilvy" wrote:

You don't need activecontrol:

If Me.MultiPage1.SelectedItem.ActiveControl.Name =
"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

--
Regards,
Tom Ogilvy



"Geoff" wrote:

The following code fails at line 2 with Object vaiable not set
and I
cannot
find the correct syntax.
The proc refers to 2 optionbutton labels in a frame on a
multipage
hence
needing to use SelectedItem.

If Me.MultiPage1.SelectedItem.ActiveControl.Name =
"fraOneDayTwoDay"
Then
If fraOneDayTwoDay.ActiveControl.TabIndex = 3 Then
lblOneDayBack.Visible = True
Else
lblTwoDayBack.Visible = True
End If
End If

T.I.A.

Geoff






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
ActiveControl problem DAACKM Excel Discussion (Misc queries) 3 September 9th 08 01:15 AM
ActiveControl Geoff Excel Programming 2 March 24th 06 01:48 PM
Calendar Control & ActiveControl Marcus B Excel Programming 0 March 15th 06 10:08 AM
userform1.activecontrol.name Italian Job Excel Programming 3 November 14th 03 12:43 PM


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