Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box Calander

Status
Not open for further replies.

Bickertk

Programmer
Aug 26, 2002
23
0
0
GB
I want to have a date box on my form where you click a button and a calander pops up. You can then click on the date and it populates the box.

I know I have seen this on the site before but cannot find it. I think someone said you have to get a programme and then use through active x.

Can anyone please advise me on this?
 
First
Create a blank form called Calendar
On the on open event input the following Code

-------------------------------------------------------------------------
Option Compare Database
Option Explicit

Public mctlDate As Control


Public Property Set DateControl(ByVal ctlDate As Control)

Set mctlDate = ctlDate

End Property

Public Property Let InitialDate(datD As Date)

Me!ctlCalendar.Value = datD

End Property

Public Sub SetAndClose()

If mctlDate Is Nothing Then
MsgBox "The DateControl property has not been set", , _
"Calendar Form Error"
Else
mctlDate = ctlCalendar.Value
End If
'TODO:
DoCmd.Close acForm, Me.Name, acSaveYes

End Sub

Public Sub ctlCalendar_Click()

SetAndClose

End Sub


Public Sub ctlCalendar_KeyUp(KeyCode As Integer, ByVal Shift As Integer)

Select Case KeyCode
Case vbKeyReturn ' carriage return
SetAndClose
Case vbKeyEscape ' escape
DoCmd.Close
End Select
DoCmd.Maximize
End Sub



Public Sub Form_Open(Cancel As Integer)
DoCmd.Restore
End Sub
==========================================================================================================================
SECOND
Create a Button named CmdCalendar on your current form
OnClick event paste this code

I called the field name (Date_From)

Private Sub CmdCalendar_Click()

Dim frmCal As Form
Dim ctlD As Control
Dim db As Database
Set db = CurrentDb()
Dim rst As Recordset
Dim recClone As Recordset
Dim intNew As Integer
Dim i As Integer, z As Integer

Me!Date_From = Now()
Set ctlD = Me!Date_From
DoCmd.OpenForm "Calendar", , , , , acHidden
Set frmCal = Forms("Calendar")
With frmCal
Set .DateControl = ctlD
.InitialDate = ctlD.Value
.Visible = True
End With

'Time_From.SetFocus

RefreshDatabaseWindow


End Sub
Hope this helps
Hymn
 
By the way very helpful, thankyou. In the code though it will not compile, it says that there is a variable not define "mctlDate = ctlCalendar.Value"

I don't know why, can you tell me what the problem is and what i have to change.



 
what version of access?
dont forget about references

Hope this helps
Hymn
 
Why don't you use the dtpicker control (microsoft date and time picker control) ?

jgf
 
I have a basic working version
in A2002 if you want it

Hope this helps
Hymn
 
Hello jigf

Where can I find DTPicker, please. I searched in Access but get no hits.

Regards
Chris Bezant
 
try doing a keyword search on Date Picker

Hope this helps
Hymn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top