Conditional when has focus

  • Thread starter Thread starter RJF
  • Start date Start date
R

RJF

I have a form called frm_ClientConv with 3 tab pages on it. (pg_01, pg_02,
pg_03)
There is an unbound control on the form called txt_FilePath.
I don’t want the txt_FilePath control to be visible when pg_03 is selected.

On the Current Event of frm_ClientConv I put the following code:

If [Screen].[ActiveControl].[Name] = "pg_03" Then

txt_FilePath.Visible = False

End If

When I open the form, I get the following error message:

“The expression you entered requires the control to be in the active window.â€

I’m fairly new to VB so I realize I could be totally off-base with the code.
Any suggestions would be so appreciated.

Thanks.
 
RJF said:
I have a form called frm_ClientConv with 3 tab pages on it. (pg_01, pg_02,
pg_03)
There is an unbound control on the form called txt_FilePath.
I don’t want the txt_FilePath control to be visible when pg_03 is
selected.

On the Current Event of frm_ClientConv I put the following code:

If [Screen].[ActiveControl].[Name] = "pg_03" Then

txt_FilePath.Visible = False

End If

When I open the form, I get the following error message:

“The expression you entered requires the control to be in the active
window.â€

I’m fairly new to VB so I realize I could be totally off-base with the
code.
Any suggestions would be so appreciated.


You can do this by checking the value of the tab control itself. You didn't
give the name of that control, but suppose it is "tabMyTab". Then your code
might be:

Me.txt_FilePath.Visible = (Me.tabMyTab <> Me.pg_03.PageIndex)
 
(re-sending, as my original reply hasn't appeared)

RJF said:
I have a form called frm_ClientConv with 3 tab pages on it. (pg_01, pg_02,
pg_03)
There is an unbound control on the form called txt_FilePath.
I don’t want the txt_FilePath control to be visible when pg_03 is
selected.

On the Current Event of frm_ClientConv I put the following code:

If [Screen].[ActiveControl].[Name] = "pg_03" Then

txt_FilePath.Visible = False

End If

When I open the form, I get the following error message:

“The expression you entered requires the control to be in the active
window.â€

I’m fairly new to VB so I realize I could be totally off-base with the
code.
Any suggestions would be so appreciated.


You can do this by checking the value of the tab control itself. You didn't
give the name of that control, but suppose it is "tabMyTab". Then your code
might be:

Me.txt_FilePath.Visible = (Me.tabMyTab <> Me.pg_03.PageIndex)
 
Hi Dirk,

Thank you for your reply and please forgive my ignorance.

Is this the only code I need to put in the On Current Event?

Me.txt_FilePath.Visible = (Me.TabCtl1 <> Me.pg_03.PageIndex)

I put the above statement in On Current of the frm_ClientConv and it works
when I first open the form (and I'm on pg_01) but it doesn't update when I
click on pg_03.

What am I doing wrong?

Thank you,
Rachel

--
RJF


Dirk Goldgar said:
(re-sending, as my original reply hasn't appeared)

RJF said:
I have a form called frm_ClientConv with 3 tab pages on it. (pg_01, pg_02,
pg_03)
There is an unbound control on the form called txt_FilePath.
I don’t want the txt_FilePath control to be visible when pg_03 is
selected.

On the Current Event of frm_ClientConv I put the following code:

If [Screen].[ActiveControl].[Name] = "pg_03" Then

txt_FilePath.Visible = False

End If

When I open the form, I get the following error message:

“The expression you entered requires the control to be in the active
window.â€

I’m fairly new to VB so I realize I could be totally off-base with the
code.
Any suggestions would be so appreciated.


You can do this by checking the value of the tab control itself. You didn't
give the name of that control, but suppose it is "tabMyTab". Then your code
might be:

Me.txt_FilePath.Visible = (Me.tabMyTab <> Me.pg_03.PageIndex)


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
RJF said:
Hi Dirk,

Thank you for your reply and please forgive my ignorance.

Is this the only code I need to put in the On Current Event?

Me.txt_FilePath.Visible = (Me.TabCtl1 <> Me.pg_03.PageIndex)

I put the above statement in On Current of the frm_ClientConv and it works
when I first open the form (and I'm on pg_01) but it doesn't update when I
click on pg_03.

What am I doing wrong?

Thank you,
Rachel


Rachel -

You'll also need to put that line of code into the Change event of the tab
control:

Private Sub TabCtl1_Change()

Me.txt_FilePath.Visible = (Me.TabCtl1 <> Me.pg_03.PageIndex)

End Sub
 
I just figured that out before I read your last message and was going to
write back that I got it.

Thank you so much for your help and the incredibly quick responses.
 
Back
Top