MSComCtl2.MonthView.2 (1 Viewer)

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:09
Joined
May 21, 2018
Messages
8,527
OK here it is. Give it a try. There are a few formatting issues, but seems to work. Now that this is built it would be easy to do a year view or six month view.

A calendar control should do 2 things only.
1. Return a date when the value changes
2. Allow you to display a selected date.

It does the first one by having an event that you can trap. It does the second by exposing a method to allow you to set the date.
Here is the code to use the control
Code:
Option Compare Database
Option Explicit

'Defing a MonthCal as below
Private WithEvents MonthCal As Form_3MonthCalendar
'On load set month cal to the subform

Private Sub Form_Load()
   Set MonthCal = Me.subFrm3month.Form
End Sub

'You can now trap the calendar change event
Private Sub MonthCal_DateChange(TheDate As Date)
   Me.fldDate = TheDate
End Sub

'You can set the value of the calendar
Private Sub fldDate_AfterUpdate()
  MonthCal.SelectedDate = fldDate
End Sub
Private Sub fldDate_Change()
  If IsDate(fldDate.Text) Then
    Me.Dirty = False
    MonthCal.SelectedDate = fldDate
  End If
End Sub
Private Sub Form_Current()
  MonthCal.SelectedDate = Nz(Me.fldDate, Date)
End Sub
CC.png
 
Last edited:

Dick7Access

Dick S
Local time
Yesterday, 20:09
Joined
Jun 9, 2009
Messages
4,201
Needs a memo field connected to each date. Would you like me to put the copy on drop box.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:09
Joined
May 21, 2018
Messages
8,527
If I have a meeting on Wed. and meeting the following Sunday 150 miles away, I can look at both dates check in the memo field and see my motel Reservation and contact names.
That’s the problem I have with calendars off the shelf. I can see if a certain day has an entry, but then have to change screens, to see the data, then change screens again to see another month.
Sorry about the small screen shot. I try making it bigger, but couldn’t

You should be able to do that yourself. Remember the calendar control does one thing, it returns a date. You have an event that returns that date. You can simply then do a dlookup to return the value associated with the date. Or if this is bound to query you can do a recordset.findfirst to move to that day. Just remember in sql when you make a where statement you date has to be #mm/dd/yyyy# regardless of your local settings.

From your image it looked like a three month date picker so that is what i built. The problem with that IMO there is no way to show that there is information for a given date. Obviously the real estate does not support having travel details in the little cells. However you could do what was shown in the original screen shot and possibly have color codes for days that have travel information. That way you can look at three months and see a different color for days that are booked and those that are not. You could even have color codes like
Depart Day
Meeting Day
Return Day
Time off
Nothing Scheduled
Etc. Similar to the year view. Then you can look at three month in this small form and get information about that day. Colors would be easier than trying to cram some text into this space. However it may be kind of ugly and not good for color blind people.
 

Dick7Access

Dick S
Local time
Yesterday, 20:09
Joined
Jun 9, 2009
Messages
4,201
You should be able to do that yourself. Remember the calendar control does one thing, it returns a date. You have an event that returns that date. You can simply then do a dlookup to return the value associated with the date. Or if this is bound to query you can do a recordset.findfirst to move to that day. Just remember in sql when you make a where statement you date has to be #mm/dd/yyyy# regardless of your local settings.

From your image it looked like a three month date picker so that is what i built. The problem with that IMO there is no way to show that there is information for a given date. Obviously the real estate does not support having travel details in the little cells. However you could do what was shown in the original screen shot and possibly have color codes for days that have travel information. That way you can look at three months and see a different color for days that are booked and those that are not. You could even have color codes like
Depart Day
Meeting Day
Return Day
Time off
Nothing Scheduled
Etc. Similar to the year view. Then you can look at three month in this small form and get information about that day. Colors would be easier than trying to cram some text into this space. However it may be kind of ugly and not good for color blind people.
No, I can't do it myself. Your VBA has me baffled. I have dabble very little in VBA. I have had no desire to study it. Thanks for trying.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:09
Joined
May 21, 2018
Messages
8,527
Kind of perplexed of what has you baffled. Not sure how any simpler this could be. It is three lines of code to make this work as I have already explained.
Code:
Option Compare Database
Option Explicit

'Defing a MonthCal as below
Private WithEvents MonthCal As Form_3MonthCalendar '1
'On load set month cal to the subform

Private Sub Form_Load()
   Set MonthCal = Me.subFrm3month.Form '2
End Sub

'You can now trap the calendar change event
Private Sub MonthCal_DateChange(TheDate As Date)
   Me.fldDate = TheDate '3
End Sub

Then as necessary a couple other lines of code to change it based on other form controls

Code:
'You can set the value of the calendar
Private Sub fldDate_AfterUpdate()
  MonthCal.SelectedDate = fldDate
End Sub
Private Sub fldDate_Change()
  If IsDate(fldDate.Text) Then
    Me.Dirty = False
    MonthCal.SelectedDate = fldDate
  End If
End Sub
Private Sub Form_Current()
  MonthCal.SelectedDate = Nz(Me.fldDate, Date)
End Su
 

Dick7Access

Dick S
Local time
Yesterday, 20:09
Joined
Jun 9, 2009
Messages
4,201
Kind of perplexed of what has you baffled. Not sure how any simpler this could be. It is three lines of code to make this work as I have already explained.
Code:
Option Compare Database
Option Explicit

'Defing a MonthCal as below
Private WithEvents MonthCal As Form_3MonthCalendar '1
'On load set month cal to the subform

Private Sub Form_Load()
   Set MonthCal = Me.subFrm3month.Form '2
End Sub

'You can now trap the calendar change event
Private Sub MonthCal_DateChange(TheDate As Date)
   Me.fldDate = TheDate '3
End Sub

Then as necessary a couple other lines of code to change it based on other form controls

Code:
'You can set the value of the calendar
Private Sub fldDate_AfterUpdate()
  MonthCal.SelectedDate = fldDate
End Sub
Private Sub fldDate_Change()
  If IsDate(fldDate.Text) Then
    Me.Dirty = False
    MonthCal.SelectedDate = fldDate
  End If
End Sub
Private Sub Form_Current()
  MonthCal.SelectedDate = Nz(Me.fldDate, Date)
End Su
As I stated, I don’t know VB. I make simple DB for my own use. Access is a very small part of my life. Its like a car. I don’t care what makes it go. I just want it to go

Lets start with this

Private WithEvents MonthCal
style='font-size:11.5pt;color:#141414'>Don’t know what this doesSet MonthCal
style='font-size:11.5pt;color:#141414'>Set MonthCal what does it mean to set
style='font-size:11.5pt;color:#141414'>If IsDate(fldDate.Text) Then
style='font-size:11.5pt;color:#141414'> Me.Dirty = False
style='font-size:11.5pt;color:#141414'>What is dirty and why is it dirty
style='font-size:11.5pt;color:#141414'>NEED I GO ON
style='font-size:11.5pt;color:#141414'>
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:09
Joined
May 21, 2018
Messages
8,527
I don’t care what makes it go. I just want it to go
I believe that is exactly what I did and always do. If I develop a solution I rarely ever tell people to modify the code. I provide input and output hooks and try to make everything else just a black box. So there are hundreds of lines of code to make this work, but no one should even look at that. You need to know 1 event and 1 property
DateChange event
SelectedDate property

1. Drop this subform onto any form you want. Call the subform control "subFrm3month"
2. Drop this code to make it work
Code:
'Define a MonthCal as below
Private WithEvents MonthCal As Form_3MonthCalendar '1

'On load set monthcal to the subform
Private Sub Form_Load()
   Set MonthCal = Me.subFrm3month.Form '2
End Sub

3. Every time the date changes in the control it fires the DateChange event. This is just like any other Access event. When that happens you can do whatever you need

Code:
'You can now trap the calendar change event
Private Sub MonthCal_DateChange(TheDate As Date)
   Me.fldDate = TheDate '3
End Su

4. I cannot demonstrate all the possible times you would want to set the value of the control, but they all take the same form

MonthCal.SelectedDate = Some date value

I demoed a couple of cases. I changed the current record. I typed into a textbox.
Code:
You can set the value of the calendar
Private Sub fldDate_AfterUpdate()
  MonthCal.SelectedDate = fldDate
End Sub
Private Sub fldDate_Change()
  If IsDate(fldDate.Text) Then
    Me.Dirty = False
    MonthCal.SelectedDate = fldDate
  End If
End Sub
Private Sub Form_Current()
  MonthCal.SelectedDate = Nz(Me.fldDate, Date)
End Su

Somehow you coded the original calendar control, so I assume you had some basic knowledge of how to get and set a value from a control. My guess it had a way to set the date of the control and a way to identify that the controls date has changed. That is exactly what I provided.
 

Dick7Access

Dick S
Local time
Yesterday, 20:09
Joined
Jun 9, 2009
Messages
4,201
I believe that is exactly what I did and always do. If I develop a solution I rarely ever tell people to modify the code. I provide input and output hooks and try to make everything else just a black box. So there are hundreds of lines of code to make this work, but no one should even look at that. You need to know 1 event and 1 property
DateChange event
SelectedDate property

1. Drop this subform onto any form you want. Call the subform control "subFrm3month"
2. Drop this code to make it work
Code:
'Define a MonthCal as below
Private WithEvents MonthCal As Form_3MonthCalendar '1

'On load set monthcal to the subform
Private Sub Form_Load()
   Set MonthCal = Me.subFrm3month.Form '2
End Sub

3. Every time the date changes in the control it fires the DateChange event. This is just like any other Access event. When that happens you can do whatever you need

Code:
'You can now trap the calendar change event
Private Sub MonthCal_DateChange(TheDate As Date)
   Me.fldDate = TheDate '3
End Su

4. I cannot demonstrate all the possible times you would want to set the value of the control, but they all take the same form

MonthCal.SelectedDate = Some date value

I demoed a couple of cases. I changed the current record. I typed into a textbox.
Code:
You can set the value of the calendar
Private Sub fldDate_AfterUpdate()
  MonthCal.SelectedDate = fldDate
End Sub
Private Sub fldDate_Change()
  If IsDate(fldDate.Text) Then
    Me.Dirty = False
    MonthCal.SelectedDate = fldDate
  End If
End Sub
Private Sub Form_Current()
  MonthCal.SelectedDate = Nz(Me.fldDate, Date)
End Su

Somehow you coded the original calendar control, so I assume you had some basic knowledge of how to get and set a value from a control. My guess it had a way to set the date of the control and a way to identify that the controls date has changed. That is exactly what I provided.
 

Dick7Access

Dick S
Local time
Yesterday, 20:09
Joined
Jun 9, 2009
Messages
4,201
No In did not make the first calendar. View post #1 "I have a calendar that someone made for me on Access" I have a nutrition tracker that somebody made for me. etc. etc. etc. Sorry I can't use what you sent me.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:09
Joined
Sep 21, 2011
Messages
14,260
I believe that is exactly what I did and always do. If I develop a solution I rarely ever tell people to modify the code. I provide input and output hooks and try to make everything else just a black box. So there are hundreds of lines of code to make this work, but no one should even look at that. You need to know 1 event and 1 property
DateChange event
SelectedDate property

1. Drop this subform onto any form you want. Call the subform control "subFrm3month"
2. Drop this code to make it work
Code:
'Define a MonthCal as below
Private WithEvents MonthCal As Form_3MonthCalendar '1

'On load set monthcal to the subform
Private Sub Form_Load()
   Set MonthCal = Me.subFrm3month.Form '2
End Sub

3. Every time the date changes in the control it fires the DateChange event. This is just like any other Access event. When that happens you can do whatever you need

Code:
'You can now trap the calendar change event
Private Sub MonthCal_DateChange(TheDate As Date)
   Me.fldDate = TheDate '3
End Su

4. I cannot demonstrate all the possible times you would want to set the value of the control, but they all take the same form

MonthCal.SelectedDate = Some date value

I demoed a couple of cases. I changed the current record. I typed into a textbox.
Code:
You can set the value of the calendar
Private Sub fldDate_AfterUpdate()
  MonthCal.SelectedDate = fldDate
End Sub
Private Sub fldDate_Change()
  If IsDate(fldDate.Text) Then
    Me.Dirty = False
    MonthCal.SelectedDate = fldDate
  End If
End Sub
Private Sub Form_Current()
  MonthCal.SelectedDate = Nz(Me.fldDate, Date)
End Su

Somehow you coded the original calendar control, so I assume you had some basic knowledge of how to get and set a value from a control. My guess it had a way to set the date of the control and a way to identify that the controls date has changed. That is exactly what I provided.
@MajP I am getting the error below when I try and open it?

I've added the code below for now?
Code:
            If Not (ctlt Is Me.ActiveControl) Then
                ctlt.Enabled = False    'Added to disable/lock text boxes without a date so data cant be entered
                ctlt.Value = Null    'Added so months lables that don't display or have a date do not show on grid
            End If

1605890555706.png
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:09
Joined
May 21, 2018
Messages
8,527
Yes. I had one fake textbox to set the control focus to. I took it out. Looks like I need to add it back. What is happening is the code is trying to disable a selected textbox. My guess this happens when a day is no longer in use. Let me send an update
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:09
Joined
Sep 21, 2011
Messages
14,260
@MajP
I have amended the first version, but would rather you do it for the request below?
Would you be able to put the date being used as the middle month on Load please.?

I have made changes and it does appear to work for now, but you know your code better than I.?

TIA

1605893645882.png


Really cool calendar as well. Thank you.

Edit: What is the Outlook reference for please?
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:09
Joined
May 21, 2018
Messages
8,527
To put the date in the center change this line
Code:
Public Property Let SelectedDate(ByVal TheDate As Date)
  mSelectedDate = TheDate
  If Me.SelectedDate < Me.startdate Or Me.SelectedDate > Me.EndDate Then
    'subtract -1 from the month
    'It will start the view 1 month prior
    Me.startdate = DateSerial(Year(Me.SelectedDate), Month(Me.SelectedDate) - 1, 1)
    LoadSubforms
  End If
  Me.txtDate = Me.SelectedDate
  Me.cboMonth = Month(Me.SelectedDate)
  Me.txtYear = Year(Me.SelectedDate)
  HighlightDate
End Property

See if this works. I put some error checking in for the focus.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:09
Joined
May 21, 2018
Messages
8,527
No In did not make the first calendar. View post #1 "I have a calendar that someone made for me on Access" I have a nutrition tracker that somebody made for me. etc. etc. etc. Sorry I can't use what you sent me
I am absolutely clueless on this. You posted a database called testupload that you built that uses a calendar control In truth that control is 10 times more complicated to use then what I provided. You have to control the movement externally. I automated all of that.
"I have a calendar that someone made for me on Access" I have a nutrition tracker that somebody made for me. etc. etc. etc. Sorry I can't use what you sent me.
Now it sounds like you need someone to build you a database not a control to use. If you want someone to build you a database we can help with that.

I built a three month calendar date picker than can be used in any database.
I have had no desire to study it. Thanks for trying
However if you have no interest in putting in any effort maybe you want to post that up front so we are not wasting our time replying to you. I enjoy building applications and I can probably use this code somewhere else so not a total loss, but if I knew you only wanted someone to build you a turn key application I definitely would not have wasted my time.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:09
Joined
Sep 21, 2011
Messages
14,260
Not doing it for me?, still in the first subform.
There is an errant reference to Outlook 16 as well.?
Also flddate does not like one trying to type in a date? Please try todays date.

Don't worry too much about it, as I said, I have a version, but that simple -1 would have been more elegant if it had worked.

I do appreciate the work you put into this, so not wasted and I dare say a few others will find it useful in the future.

Thank you.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:09
Joined
May 21, 2018
Messages
8,527
@Gasman
Try this. It works for me. This would not have worked as a standalone if you were trying it that way.

This is not so elegant IMO because the Month control is what changes the displayed month. So the date may be in september but the month control is august. I could move the month control over the middle subform if that is intuitive.

You should be able to type in fld date. However, it no longer uses an onchange event. That means after you update the date you will have to either hit return or move the focus so the field updates. The issue is the field is still dirty until you leave so the calendar cannot update.

I also demo a popup version. Still has a single event, but now it only fires on the OK button.
 

Attachments

  • MultiMonthCalendar v6.accdb
    652 KB · Views: 102
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 01:09
Joined
Sep 21, 2011
Messages
14,260
Yes, that does it now.
I had also commented out the OnChange event on my version V3.

Thanks again.
 

Dick7Access

Dick S
Local time
Yesterday, 20:09
Joined
Jun 9, 2009
Messages
4,201
I have downloaded a couple of Excel calendars, templates to try and use until I get my Access calendar problem straighten out but none of them work properly. Anybody out there have a simple Excel Calendar I can download. No start and finish dates and times.
 

Dick7Access

Dick S
Local time
Yesterday, 20:09
Joined
Jun 9, 2009
Messages
4,201
I have downloaded a couple of Excel calendars, templates to try and use until I get my Access calendar problem straighten out but none of them work properly. Anybody out there have a simple Excel Calendar I can download. No start and finish dates and times.
Ps needs a area for data
 

Users who are viewing this thread

Top Bottom