Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27193

VS 2010 Monthview Calendar VBA in Excel - make input date compulsory

$
0
0
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

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)
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.

Anyone any ideas and where the code should be placed?

Viewing all articles
Browse latest Browse all 27193

Trending Articles