Making a calendar type thing (1 Viewer)

Hawkins1989

New member
Local time
Today, 12:17
Joined
Jan 25, 2018
Messages
10
Hi,

I wonder if someone could please help me, I have a form which has a lot of list boxes and text boxes above them - the text boxes hold dates and the list boxes show people who are attending on that date.

Currently the first box shows the monday of the current week and the rest populate with the next 4 weeks which is ok but I would like to have a combo box at the top with the months in and what ever month is selected the first box goes to the first week of the month - if the 1st is a monday then great but if not then how do I get the closest monday to the first of the month ie. goes back to the 31st or 30th etc.

Basically I want it to work a bit like a calendar.

I have searched the internet but I haven't been able to find anything that I could make work for what I want.

I think the combo box may need to use a select case option for each month but I can't think of what the code would be.

Many thanks for any help you wonderful people can offer
M
P.s you will have to dumb it down a bit for me as I'm not that great at VBA.
 

isladogs

MVP / VIP
Local time
Today, 12:17
Joined
Jan 14, 2017
Messages
18,272
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:17
Joined
May 7, 2009
Messages
19,249
first, you should increase the number of textboxes, there are times there are
5 monday (weeks) on a month.

second, your New combobox should have the number of month as first column, eg:

1,"January"
2,"February"
3,"March"
...etc...

copy this in the new Module:
Code:
' agp
Public Function FindNextDOW(dte As Date, whatDay As VbDayOfWeek) As Date
   FindNextDOW = dte + 7 - Weekday(dte + 7 - whatDay)
   If FindNextDOW = dte Then FindNextDOW = FindNextDOW + 7
End Function

on the afterupdate event of the new combo:
Code:
private sub cboMonth_AfterUpdate()
me.txtMonday1 = FindNextDOW(DateSerial(Year(Date), cboMonth, 1), vbMonday)
me.txtMonday2 = FindNextDOW(me.txtMonday1, vbMonday)
me.txtMonday3 = FindNextDOW(me.txtMonday2, vbMonday)
me.txtMonday4 = FindNextDOW(me.txtMonday3, vbMonday)
end sub
 

Hawkins1989

New member
Local time
Today, 12:17
Joined
Jan 25, 2018
Messages
10
Thank you guys for the help.

@ArnelGP this solution worked a treat I tweaked it a little without managing to break it completely so i will get the monday of whatever week the first of the month is on this will be very useful for the purpose of the database

Thank you all very much
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:17
Joined
May 7, 2009
Messages
19,249
you're welcome!
 

Users who are viewing this thread

Top Bottom