Access VBA for defining a text box based on Tabs

ARW17

Board Regular
Joined
Oct 31, 2016
Messages
109
I want to create a text box whose value is equal to the caption on the tab that is currently active.

For example, my tabs are dates. The first tab is today's date and the next 4 are the next 4 work dates.

I want the text box to say Fri 1/20, when the Fri 1/20 tab is selected and the change to Tue 1/24 when the Tue 1/24 tab is selected.

I'm not sure how to write this in VBA, but I basically want something like:

If the tab named "Today" is selected then
txtTab = Today.caption
If the tab named "TodayPlus1" is selected then
txtTab = TodayPlus1.caption
End If
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
This worked:

Private Sub DayTabs_Click()
If DayTabs.Pages(DayTabs.Value).Name = "Today" Then
txtTab = Today.Caption
End If
If DayTabs.Pages(DayTabs.Value).Name = "TodayPlus1" Then
txtTab = TodayPlus1.Caption
End If
If DayTabs.Pages(DayTabs.Value).Name = "TodayPlus2" Then
txtTab = TodayPlus2.Caption
End If
If DayTabs.Pages(DayTabs.Value).Name = "TodayPlus3" Then
txtTab = TodayPlus3.Caption
End If
If DayTabs.Pages(DayTabs.Value).Name = "TodayPlus4" Then
txtTab = TodayPlus4.Caption
End If
End Sub

I also set the default as [Today].[Caption]
 
Upvote 0
or this?
Private Sub DayTabs_Change()
MsgBox Me.TabCtl28.Pages(Me.TabCtl28.Value).Caption
End Sub

or this?
Private Sub DayTabs_Click()
txtTab = Me.DayTabs.Pages(Me.DayTabs.Value).Caption
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top