add date from calendar (1 Viewer)

md-rahim

Registered User.
Local time
Today, 15:45
Joined
Dec 7, 2012
Messages
36
Dear all

I want to add a date from viewing the calendar. When I click on the date text box then want to see the calendar and I will choose the date and that date will appear in the text box. Plaza help me
 

missinglinq

AWF VIP
Local time
Today, 04:45
Joined
Jun 20, 2003
Messages
6,423
What version of Access are you running? In versions 2007/2010/2013 this is should occur automatically, unless you've changed the default settings for the Textbox.
  • If the Textbox is bound to a Field the Field must be defined as a DateTime Field (at Table-level)
  • If the Textbox is Unbound it must be set to a Date or Time Format (at Form-level)
  • Show Date Picker must be set to For Dates Only (this can be done at the Table-level or Form-level)
That's it. When you enter the Textbox the Calendar Icon will pop up. Click on the icon and click on a date; the Textbox will be populated with the selected date.

Linq ;0)>
 

AlexHedley

Registered User.
Local time
Today, 09:45
Joined
Aug 28, 2012
Messages
171
You can also use

Code:
Application.RunCommand (acCmdShowDatePicker)
 

missinglinq

AWF VIP
Local time
Today, 04:45
Joined
Jun 20, 2003
Messages
6,423
Used in the GotFocus event of a DateTime Textbox, as defined above, the code ALex gave

Application.RunCommand (acCmdShowDatePicker)

or

DoCmd.RunCommand acCmdShowDatePicker

will cause the DatePicker to popup up when the Texbox is entered, doing away with the necessity of clicking on the icon.

Code:
Private Sub YourDateField_GotFocus()
  DoCmd.RunCommand acCmdShowDatePicker
End Sub

If you only want the Datepicker to pop up if the Textbox doesn't already have a Date in it:

Code:
Private Sub YourDateField_GotFocus()
 If Nz(Me.YourDateField, "") = "" Then
  DoCmd.RunCommand acCmdShowDatePicker
 End If
End Sub
Linq ;0)>
 

md-rahim

Registered User.
Local time
Today, 15:45
Joined
Dec 7, 2012
Messages
36
Dear

where the Date Picker option. how I can add it. I'm using office 2002.

can u give me any sample plz

plz
 

AlexHedley

Registered User.
Local time
Today, 09:45
Joined
Aug 28, 2012
Messages
171
Have a read through of the following Calendar Picker Blog Post.

You could use an Active X Calendar Picker Control.
It doesn't work in later versions of Access which is why the below was suggested and Access added the inbuilt functionality.

If you want an indepth tutorial on Calendars check out the Calendar Seminar
 

missinglinq

AWF VIP
Local time
Today, 04:45
Joined
Jun 20, 2003
Messages
6,423
Best practice when using a calendar in pre-2007 Access is to use a Form-based calendar, rather than an ActiveX Calendar, for the reason Alex gave; ActiveX Controls that work on one version of Access frequently will not work when another version of Access is used. A Form-based calendar, on the other hand, will work on later versions.

There are a number of these hacks available, on the web, but Allen Browne has an excellent one available on his site. After downloading the app, you can run it and a screen comes up giving you the very simply instructions ( I think it's every bit of four or five lines long) needed to use the calendar in your database:

http://allenbrowne.com/ser-51.html

Linq ;0)>
 

Dragonous24

New member
Local time
Today, 09:45
Joined
Feb 6, 2020
Messages
15
Used in the GotFocus event of a DateTime Textbox, as defined above, the code ALex gave

Application.RunCommand (acCmdShowDatePicker)

or

DoCmd.RunCommand acCmdShowDatePicker

will cause the DatePicker to popup up when the Texbox is entered, doing away with the necessity of clicking on the icon.

Code:
Private Sub YourDateField_GotFocus()
  DoCmd.RunCommand acCmdShowDatePicker
End Sub

If you only want the Datepicker to pop up if the Textbox doesn't already have a Date in it:

Code:
Private Sub YourDateField_GotFocus()
If Nz(Me.YourDateField, "") = "" Then
  DoCmd.RunCommand acCmdShowDatePicker
End If
End Sub
Linq ;0)>

This works great on normal forms, but doesnt seem to work when run from a subform (subform is a continuous form). any idea why?
"Run-time error '2046': command or action 'ShowDatePicker' isnt available now"
 

Micron

AWF VIP
Local time
Today, 04:45
Joined
Oct 20, 2018
Messages
3,478
you probably aren't referring to the subform correctly, but that's just a guess because you didn't provide any code for your attempt.

referencing CONTROLS on subform:
[Forms]![Main form name]![subform control name].[Form]![control name on subform]

e.g.
[Forms]![frmNP]![subNPfrm].[Form]![txtNPno]
frmNP is main form name
subNPfrm is name of subform control on frmNP
txtNPno is the textbox control name
 

Dragonous24

New member
Local time
Today, 09:45
Joined
Feb 6, 2020
Messages
15
you probably aren't referring to the subform correctly, but that's just a guess because you didn't provide any code for your attempt.

referencing CONTROLS on subform:
[Forms]![Main form name]![subform control name].[Form]![control name on subform]

e.g.
[Forms]![frmNP]![subNPfrm].[Form]![txtNPno]
frmNP is main form name
subNPfrm is name of subform control on frmNP
txtNPno is the textbox control name

im using the code:

Private Sub fld_Date_trec_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DoCmd.RunCommand acCmdShowDatePicker
End Sub


this code is on the subform.

Main form is "frmPersonnel"
Subform Control Name is "SubFrmHistory"
Subform name is "frm_Personnel_sub_history"

how do i modify the code to get it working?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:45
Joined
Oct 29, 2018
Messages
21,485
im using the code:

Private Sub fld_Date_trec_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DoCmd.RunCommand acCmdShowDatePicker
End Sub


this code is on the subform.

Main form is "frmPersonnel"
Subform Control Name is "SubFrmHistory"
Subform name is "frm_Personnel_sub_history"

how do i modify the code to get it working?
Hi. Assuming fld_Date_trec is bound to a date/time field, do you have anything in its Format property? Just curious...
 

Dragonous24

New member
Local time
Today, 09:45
Joined
Feb 6, 2020
Messages
15
Hi. Assuming fld_Date_trec is bound to a date/time field, do you have anything in its Format property? Just curious...

yea fld_date_trec is the date field and has no format applied.

The code works fine when the form is opened on its own, but fails when opened as a subform.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:45
Joined
Oct 29, 2018
Messages
21,485
yea fld_date_trec is the date field and has no format applied.

The code works fine when the form is opened on its own, but fails when opened as a subform.
Okay, that's useful information. What happens if you use the Focus event instead? Same problem?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:45
Joined
Oct 29, 2018
Messages
21,485
Yea same error.
Okay. It may be something obvious we can't see from here. Let's forget about the code for the moment. What happens if you click into the field in the subform? Do you see the date picker button show up?
 

Dragonous24

New member
Local time
Today, 09:45
Joined
Feb 6, 2020
Messages
15
Okay. It may be something obvious we can't see from here. Let's forget about the code for the moment. What happens if you click into the field in the subform? Do you see the date picker button show up?

Yes, when the field has focus the datepicker icon is floating to the right as normal and work as expected.
Edit: Actually its not working properly, let me get back you when I sort this out.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:45
Joined
Oct 29, 2018
Messages
21,485
Yes, when the field has focus the datepicker icon is floating to the right as normal and work as expected.
Okay, that verifies the date picker could be available. Unfortunately, it would be hard at this point to say exactly why it's not available without being able to review your db. Are you able to post a sample copy?
 

Dragonous24

New member
Local time
Today, 09:45
Joined
Feb 6, 2020
Messages
15
Okay, that verifies the date picker could be available. Unfortunately, it would be hard at this point to say exactly why it's not available without being able to review your db. Are you able to post a sample copy?
Heres a basic example of the issue.
open frmpersonnel_sub_history, code works fine.
open frmpersonnel where "frmpersonnel_sub_history" is embedded as a subform and it doesnt.
 

Attachments

  • Database1.zip
    21.8 KB · Views: 102

theDBguy

I’m here to help
Staff member
Local time
Today, 01:45
Joined
Oct 29, 2018
Messages
21,485
Heres a basic example of the issue.
open frmpersonnel_sub_history, code works fine.
open frmpersonnel where "frmpersonnel_sub_history" is embedded as a subform and it doesnt.
Okay, thanks. I'll take a look once I get in front of a computer, unless someone beats me to it.
 

Users who are viewing this thread

Top Bottom