How do I change the default tab in a tabbed form?

  • Thread starter Thread starter Jeffrey K. Ries
  • Start date Start date
J

Jeffrey K. Ries

I have seven tabs in a form one labeled for each day of the week. How can I
have the correct tab open by default for each day. (i.e. on Wednesday I
would like the form to automatically open to the Wednesday tab)

Thanks,
Jeffrey K. Ries
 
In the Load event of your form, set the Value of your tab control to one
less than the weekday of the date:

Private Sub Form_Load()
Me.[NameOfYourTabControlHere].Value = Weekday(Date) - 1
End Sub
 
In the On Open event,

Dim intDOW As Integer
intDOW = Weekday(Now())
' Weekday returns 1 for Sunday, 2 for Monday, etc.

Select Case intDOW
Case 1
Me.SundayPageName.SetFocus
Case 2
Me.MondayPageName.SetFocus
...
Case 7
Me.SaturdayPageName.SetFocus
End Case

HTH
Kevin Sprinkel
 
Allen,

Thank you for the prompt response. I inputed your code and it worked,
kinda. It went to the wrong day. I changed the code to "- 2" and it went
to Monday as it should.

I am extremely new to VBA. Will this change end up biting me later?

Jeffrey K. Ries


Allen Browne said:
In the Load event of your form, set the Value of your tab control to one
less than the weekday of the date:

Private Sub Form_Load()
Me.[NameOfYourTabControlHere].Value = Weekday(Date) - 1
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jeffrey K. Ries said:
I have seven tabs in a form one labeled for each day of the week. How
can
I
have the correct tab open by default for each day. (i.e. on Wednesday I
would like the form to automatically open to the Wednesday tab)

Thanks,
Jeffrey K. Ries
 
Forget it, I found the error myself by changing the system date and running
the form. Sunday produced an error so I altered the code to read as
follows:

Me.[Tabbed Set].Value = Weekday(Date,vbMonday) - 1

This made Monday the first day of the week and all code now works perfectly.

Thanks again,
Jeffrey K. Ries


Allen Browne said:
In the Load event of your form, set the Value of your tab control to one
less than the weekday of the date:

Private Sub Form_Load()
Me.[NameOfYourTabControlHere].Value = Weekday(Date) - 1
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jeffrey K. Ries said:
I have seven tabs in a form one labeled for each day of the week. How
can
I
have the correct tab open by default for each day. (i.e. on Wednesday I
would like the form to automatically open to the Wednesday tab)

Thanks,
Jeffrey K. Ries
 
Back
Top