I am working on a project in order to learn VBA and need a popup calendar to enable the user to input an incident date (it is a motor claims training exercise).
I have managed to create a calendar using MonthView and restricted date selected so that it cannot be in the future. This produces a message box telling user date invalid and goes back to showing calendar.
However, I can't seem to find any code to prevent the user pressing escape or red cross to close as the incident date is 'compulsory'. (It is needed to evaluate the driver's date of birth so same will be needed for that part of the project).
The following is in the DateClick of MonthView1
Anyone any ideas and where the code should be placed?
I have managed to create a calendar using MonthView and restricted date selected so that it cannot be in the future. This produces a message box telling user date invalid and goes back to showing calendar.
However, I can't seem to find any code to prevent the user pressing escape or red cross to close as the incident date is 'compulsory'. (It is needed to evaluate the driver's date of birth so same will be needed for that part of the project).
The following is in the DateClick of MonthView1
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
On Error Resume Next
'this checks the input date is not in the future
If frmCalendar.MonthView1.Value > Date Then
MsgBox "You have selected a future date, please try again!", vbOKOnly
Else
Range("F9").Value = DateClicked
Unload frmCalendar 'can use unload me instead
End If
End Sub
(the following is to set Date)On Error Resume Next
'this checks the input date is not in the future
If frmCalendar.MonthView1.Value > Date Then
MsgBox "You have selected a future date, please try again!", vbOKOnly
Else
Range("F9").Value = DateClicked
Unload frmCalendar 'can use unload me instead
End If
End Sub
Private Sub UserForm_Initialize()
frmCalendar.MonthView1.Value = Date ' this sets the calendar date to the computers current date i.e. today
End Sub
I obviously can't use if.....date.value = "" as it has the value for today's date but thought I could use an if statement to capture if escape or cancel (using x) was clicked and can't seem to find anything. frmCalendar.MonthView1.Value = Date ' this sets the calendar date to the computers current date i.e. today
End Sub
Anyone any ideas and where the code should be placed?