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

  • Thread starter Jeffrey K. Ries
  • 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
 
A

Allen Browne

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
 
K

Kevin Sprinkel

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
 
J

Jeffrey K. Ries

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
 
J

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
 

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