Text box to display name of current active tab returning #Name?

C

Clddleopard

I have a tab control on a form with a form showing through behind it. The
query for the form refreshes when switching tabs and is supposed to use the
name of the active tab as one of the criteria for the query. I do this by
referencing a text box on the form named "tab" that has the following set as
its control source:
=[TabCtl0].[Pages]([TabCtl0]).[Name]

I swear that at one point this used to work, but now I get #Name? instead
of the tab's name in the text box, which obviously screws up my query. Any
idea why this would stop working?

Hope it's something simple!
 
K

ken

I'm surprised you are getting the error; I'd have thought it more
likely that the text box's value would stick at the name of tab
control's default page.

As you are presumably requerying the form in the tab control's Change
event procedure you can 'push' the value into the text box in the
procedure:

Dim ctrl As Control

Set ctrl = Me.TabCtl0

Me.YourTextBox = ctrl.Pages(ctrl).Name
Me.Requery

Leave the text box's ControlSource property blank. You'd need to
execute the same code in the form's open event procedure to initialize
the value of the text box, so it would be better to wrap the code in a
function in the form's module and call the function as each of the
event properties rather than repeating the code.

Ken Sheridan
Stafford, England
 
C

Clddleopard

Great, that worked. Thanks a lot!
I was also surprised that I was getting the #name? error instead of just
having the text box stick to one. When it was working though, it did change
the text box when I changed tabs. Not sure what caused it to stop working
initially...

I'm surprised you are getting the error; I'd have thought it more
likely that the text box's value would stick at the name of tab
control's default page.

As you are presumably requerying the form in the tab control's Change
event procedure you can 'push' the value into the text box in the
procedure:

Dim ctrl As Control

Set ctrl = Me.TabCtl0

Me.YourTextBox = ctrl.Pages(ctrl).Name
Me.Requery

Leave the text box's ControlSource property blank. You'd need to
execute the same code in the form's open event procedure to initialize
the value of the text box, so it would be better to wrap the code in a
function in the form's module and call the function as each of the
event properties rather than repeating the code.

Ken Sheridan
Stafford, England

I have a tab control on a form with a form showing through behind it. The
query for the form refreshes when switching tabs and is supposed to use the
name of the active tab as one of the criteria for the query. I do this by
referencing a text box on the form named "tab" that has the following set as
its control source:
=[TabCtl0].[Pages]([TabCtl0]).[Name]

I swear that at one point this used to work, but now I get #Name? instead
of the tab's name in the text box, which obviously screws up my query. Any
idea why this would stop working?

Hope it's something simple!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top