Crate a Form with the Calendar control named: frmCalendarControl
Add a button next to the date field on your regular form and add this code
to the OnClick Event.
Call DateCheck_MEI(Me!YourDateField)
Create a New Module – add this code:
Public Function GetDate_MEI(Optional varDate As Variant) As Variant
On Error Resume Next
' If varTempDate is missing then use today's date.
' Otherwise, set the date to the date passed.
Dim varTempDate As Variant
' Set calendar date
varTempDate = IIf(IsMissing(varDate), Date, varDate)
' Validate date
If Not IsDate(varTempDate) Then varTempDate = Date
DoCmd.OpenForm "frmCalendarControl", , , , , acDialog, varTempDate
' If frmCalendarControl is still loaded, then the user clicked OK so get
the
' date from the form. If the form isn't open return a value of Null.
If IsLoaded_MEI("frmCalendarControl") Then
GetDate_MEI = Forms("frmCalendarControl").Calendar1.Value
DoCmd.Close acForm, "frmCalendarControl"
Else
GetDate_MEI = Null
End If
End Function
Sub DateCheck_MEI(ctlDate As TextBox)
On Error GoTo Err_Trap
Dim datepassed As Variant
datepassed = ctlDate
ctlDate = GetDate_MEI(datepassed)
Err_Trap_Exit:
Exit Sub
Err_Trap:
MsgBox Err.Description
Resume Err_Trap_Exit
End Sub
Function IsLoaded_MEI(ByVal strFormName As String) As Integer
'------------------------------------------------------------------------------------------------------------
' Comments : Determines if the specified form is open
' Parameters: Name of Form
' Returns : True if the specified form is open in Form view or Datasheet
view.
'------------------------------------------------------------------------------------------------------------
On Error Resume Next
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded_MEI = True
End If
End If
End Function