Inserting a calendar

S

Steve

Hi

Hope you can help. A little new to Access. Actually
picked it up yesterday to write a database for my wifes
work.

Anyway, would like to add a calendar control to my form
but I can't seem to get my date field to update when I
select the date from the calendar.

Can anyone help or is there a web site where I can look
at examples.

Many Thanks

Steve
 
B

Bob Barnes

I have code for that at Work. Will send the code
to you tomorrow AM. I'm in Kentucky, USA.

HTH - Bob
 
V

Van T. Dinh

Try binding the Calendar Control to your DateField.

Open you Form in DesignView, select the Calendar Control,
open the Properties window. In the ControlSource of the
Data tab, select your DateField.

HTH
Van T. Dinh
MVP (Access)
 
S

Steve

Have tried this but still not working.

When I select the date and then click the mouse in the
date field it does update but not when I just select the
date.

Sorry, I must be doing something wrong (obviously)

Regards

Steve
 
B

Bob Barnes

Steve -

Use the MS Calendar Control.

The code is. . .(The Calendar Control is named "calCtl1") -
"AAScrap" is a textbox using a Date.

Note: The Calendar Control Properties box does not
show "On ClicK". You get to that from inside the Form
module by selecting "calCtl1" in the top left Dropdown,
then get "Click" from the top Right Dropdown. I'm also
posting in the Newsgroup should others need this.
Let me know how it works.

Private Sub calCtl1_Click()
AAScrap = calCtl1.Value: AAScrap.SetFocus
calCtl1.Visible = False
End Sub

I also use a small Button. . .
Private Sub cmdCal_Click()
On Error GoTo AAA1
calCtl1.Visible = True
If Not IsNull(AAScrap) Then
Me.calCtl1.Value = AAScrap
Else
Me.calCtl1.Value = Date
End If
AAA2:
Exit Sub
AAA1:
MsgBox Err.Description
Resume AAA2
End Sub

HTH - Bob
 
V

Van T. Dinh

Sorry, I am not following what you described.

Do you have a TextBox bound to the Date as well as a
Calendar Control bound to the Date Field?

I normally only have a TextBox bound to the DateField and
a CommandButton to open a Dialog Form with only the
unbound Calendar Control + a "Select" CommandButton. The
code for the CommandButton to open the Calendar Form:

****
Private Sub cmdFromDateCal_Click()
'================
' Form_frmPrePivot_LL.cmdFromDateCal_Click
'--------
' Purpose:
'--------
' Notes :
'--------
' Parameters:
'
'--------
' Called Subs/Functions
' (none)
'--------
' Calling Subs/Functions
' (none)
'--------
' Returns:
' (none)
'--------
' Author : Van T. Dinh, Thursday, 5 June 2003
'--------
' Revision History
' Thursday, 5 June 2003 (VTD):
'================

On Error GoTo cmdFromDateCal_Click_Err
DoCmd.OpenForm "frmCalendar", , , , , acDialog, "Select
Results From"
Me.txtFromDate.Value = Forms!
frmCalendar.acxCalendar.Value
DoCmd.Close acForm, "frmCalendar", acSaveNo

cmdFromDateCal_Click_Exit:
Exit Sub

cmdFromDateCal_Click_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " &
Err.Description & vbCrLf & vbCrLf & _
"(Programmer's note:
Form_frmPrePivot_LL.cmdFromDateCal_Click)" & vbCrLf, _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume cmdFromDateCal_Click_Exit
End Sub
****

which actually assigns the Calendar date value to the
TextBox.

The code in the Calendar Form for example:

****
Private Sub acxCalendar_DblClick()
'================
' Form_frmCalendar.acxCalendar_DblClick
'--------
' Purpose:
'--------
' Notes :
'--------
' Parameters:
'
'--------
' Called Subs/Functions
' (none)
'--------
' Calling Subs/Functions
' (none)
'--------
' Returns:
' (none)
'--------
' Author : Van T. Dinh, Friday, 27 June 2003
'--------
' Revision History
' Friday, 27 June 2003 (VTD):
'================
On Error GoTo acxCalendar_DblClick_Err
Call cmdSelect_Click

acxCalendar_DblClick_Exit:
Exit Sub

acxCalendar_DblClick_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " &
Err.Description & vbCrLf & vbCrLf & _
"(Programmer's note:
Form_frmCalendar.acxCalendar_DblClick)" & vbCrLf, _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume acxCalendar_DblClick_Exit
End Sub

Private Sub cmdSelect_Click()
'================
' Form_frmCalendar.cmdSelect_Click
'--------
' Purpose:
'--------
' Notes :
'--------
' Parameters:
'
'--------
' Called Subs/Functions
' (none)
'--------
' Calling Subs/Functions
' (none)
'--------
' Returns:
' (none)
'--------
' Author : Van T. Dinh, Monday, 16 June 2003
'--------
' Revision History
' Monday, 16 June 2003 (VTD):
'================
On Error GoTo cmdSelect_Click_Err
Me.Visible = False

cmdSelect_Click_Exit:
Exit Sub

cmdSelect_Click_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " &
Err.Description & vbCrLf & vbCrLf & _
"(Programmer's note:
Form_frmCalendar.cmdSelect_Click)" & vbCrLf, _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume cmdSelect_Click_Exit
End Sub

Private Sub Form_Current()
'================
' Form_frmCalendar.Form_Current
'--------
' Purpose:
'--------
' Notes :
'--------
' Parameters:
'
'--------
' Called Subs/Functions
' (none)
'--------
' Calling Subs/Functions
' (none)
'--------
' Returns:
' (none)
'--------
' Author : Van T. Dinh, Monday, 16 June 2003
'--------
' Revision History
' Monday, 16 June 2003 (VTD):
'================
On Error GoTo Form_Current_Err
Me.acxCalendar.Today

Form_Current_Exit:
Exit Sub

Form_Current_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " &
Err.Description & vbCrLf & vbCrLf & _
"(Programmer's note:
Form_frmCalendar.Form_Current)" & vbCrLf, _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume Form_Current_Exit
End Sub

Private Sub Form_Open(Cancel As Integer)
'================
' Form_frmCalendar.Form_Open
'--------
' Purpose:
'--------
' Notes :
'--------
' Parameters:
' Cancel (Integer)
'--------
' Called Subs/Functions
' (none)
'--------
' Calling Subs/Functions
' (none)
'--------
' Returns:
' (none)
'--------
' Author : Van T. Dinh, Monday, 16 June 2003
'--------
' Revision History
' Monday, 16 June 2003 (VTD):
'================
On Error GoTo Form_Open_Err
DoCmd.Restore
If IsNull(Me.OpenArgs) = False Then Me.Caption =
Me.OpenArgs
'Me.acxCalendar.Today (does not work)

Form_Open_Exit:
Exit Sub

Form_Open_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " &
Err.Description & vbCrLf & vbCrLf & _
"(Programmer's note: Form_frmCalendar.Form_Open)"
& vbCrLf, _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume Form_Open_Exit
End Sub
****

HTH
Van T. Dinh
MVP (Access)
 

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