Calendar Control - HELP

G

Guest

1. I have a calendar control on my form. I'm trying to have it use the system
clock for dates. I've tried making the control source a field in the
underlying table of the form with the =Date( ) but that only gives me todays
date if i select that records on the form. How do i make the default date on
the calendar to be todays date?
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top