P
PPCO
I am using Martin Green's instructions for adding a calendar to an Access form.
It works great except if I click on today's date, it enters 12:00:00 AM. It
only does this the first time. If I enter any other date, it works fine. Or
if I enter another date other than today and then enter today's date, it
works fine. If I switch the format field to short date; it puts in
12/31/1899. Thanks!
Here is my code:
Option Compare Database
Private Sub cboDate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
ocxCalendar.Visible = True
ocxCalendar.SetFocus
If Not IsNull(cboDate) Then
ocxCalendar.Value = cboDate.Value
Else
ocxCalendar.Value = Date
End If
End Sub
Private Sub Ctl_New_Click()
DoCmd.GoToRecord acActiveDataObject, , acNewRec
DoCmd.GoToControl "cboDate"
End Sub
Private Sub Form_Load()
If Not Me.NewRecord Then
RunCommand acCmdRecordsGoToNew
End If
End Sub
Private Sub Command16_Click()
On Error GoTo Err_Command16_Click
DoCmd.GoToRecord , , acNext
Exit_Command16_Click:
Exit Sub
Err_Command16_Click:
MsgBox Err.Description
Resume Exit_Command16_Click
End Sub
Private Sub ocxCalendar_Click()
cboDate.Value = ocxCalendar.Value
cboDate.SetFocus
ocxCalendar.Visible = False
End Sub
Private Sub Previous_Record_Click()
On Error GoTo Err_Previous_Record_Click
DoCmd.GoToRecord , , acPrevious
Exit_Previous_Record_Click:
Exit Sub
Err_Previous_Record_Click:
MsgBox Err.Description
Resume Exit_Previous_Record_Click
End Sub
Private Sub NEXT_RECORD_Click()
On Error GoTo Err_NEXT_RECORD_Click
DoCmd.GoToRecord , , acNext
Exit_NEXT_RECORD_Click:
Exit Sub
Err_NEXT_RECORD_Click:
MsgBox Err.Description
Resume Exit_NEXT_RECORD_Click
End Sub
Private Sub EXIT_FORM_Click()
On Error GoTo Err_EXIT_FORM_Click
DoCmd.Close
Exit_EXIT_FORM_Click:
Exit Sub
Err_EXIT_FORM_Click:
MsgBox Err.Description
Resume Exit_EXIT_FORM_Click
End Sub
It works great except if I click on today's date, it enters 12:00:00 AM. It
only does this the first time. If I enter any other date, it works fine. Or
if I enter another date other than today and then enter today's date, it
works fine. If I switch the format field to short date; it puts in
12/31/1899. Thanks!
Here is my code:
Option Compare Database
Private Sub cboDate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
ocxCalendar.Visible = True
ocxCalendar.SetFocus
If Not IsNull(cboDate) Then
ocxCalendar.Value = cboDate.Value
Else
ocxCalendar.Value = Date
End If
End Sub
Private Sub Ctl_New_Click()
DoCmd.GoToRecord acActiveDataObject, , acNewRec
DoCmd.GoToControl "cboDate"
End Sub
Private Sub Form_Load()
If Not Me.NewRecord Then
RunCommand acCmdRecordsGoToNew
End If
End Sub
Private Sub Command16_Click()
On Error GoTo Err_Command16_Click
DoCmd.GoToRecord , , acNext
Exit_Command16_Click:
Exit Sub
Err_Command16_Click:
MsgBox Err.Description
Resume Exit_Command16_Click
End Sub
Private Sub ocxCalendar_Click()
cboDate.Value = ocxCalendar.Value
cboDate.SetFocus
ocxCalendar.Visible = False
End Sub
Private Sub Previous_Record_Click()
On Error GoTo Err_Previous_Record_Click
DoCmd.GoToRecord , , acPrevious
Exit_Previous_Record_Click:
Exit Sub
Err_Previous_Record_Click:
MsgBox Err.Description
Resume Exit_Previous_Record_Click
End Sub
Private Sub NEXT_RECORD_Click()
On Error GoTo Err_NEXT_RECORD_Click
DoCmd.GoToRecord , , acNext
Exit_NEXT_RECORD_Click:
Exit Sub
Err_NEXT_RECORD_Click:
MsgBox Err.Description
Resume Exit_NEXT_RECORD_Click
End Sub
Private Sub EXIT_FORM_Click()
On Error GoTo Err_EXIT_FORM_Click
DoCmd.Close
Exit_EXIT_FORM_Click:
Exit Sub
Err_EXIT_FORM_Click:
MsgBox Err.Description
Resume Exit_EXIT_FORM_Click
End Sub