By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

Calendar Option for Date field

P: 56
hello everyone!
I would like to add a calenda option onto the form next to the Date field, so that user can just select the date from the calendar instead of typing the date, can someone help?

thanks!
bluemoon
Oct 14 '08 #1
Share this Question
Share on Google+
15 Replies


NeoPa
Expert Mod 15k+
P: 31,494
When using the Toolbox toolbar (Form design) there is an option at the end called "More Controls". In there you should find a standard one called "Calendar Control n.n".
Oct 14 '08 #2

P: 56
thanks! but then I would like to hide the calenda until user click on a little button next to the Date field. I was thinking of add a command button next to the Date field, when user click on the command button, calenda open as a dialog form. Does it work that way? is there any other better way, since I have about 10 date fields, I would have to make 10 pop up dialog forms.

thanks!
bluemoon
Oct 14 '08 #3

P: 56
Hi,
What I did was I put the calenda next to the Date field and set Visible=No, then I put a command button next to the date field, when user click on the command button, I made the calenda visible=true, but then I don't know how to make the calenda visibile=false when user is done with date selection.

thanks!

bluemoon
Oct 14 '08 #4

NeoPa
Expert Mod 15k+
P: 31,494
How about setting up an AfterUpdate event procedure for the control that is being set by the Calendar control. When that runs it can set the Calendar control back to invisible.

You could even make the showing of it triggered by entering the other control (On Enter) instead of having to add loads of Command Buttons.

Sound like an idea?
Oct 14 '08 #5

P: 56
NeoPa,
You mean to add the code "me.calenda.visible=false" onto the AfterUpdate of the DateField? I did that but it did't really work.
In the calenda Event Property, it only has 5 events: On Updated, On enter, On Exit, On Got Focus and On Lost Focus, I've tried them all and nothing works. Please help.

thanks!
Bluemoon
Oct 14 '08 #6

NeoPa
Expert Mod 15k+
P: 31,494
NeoPa,
You mean to add the code "me.calenda.visible=false" onto the AfterUpdate of the DateField? I did that but it did't really work.
I do mean that. In what way do you mean it didn't work.
Oct 14 '08 #7

P: 56
I do mean that. In what way do you mean it didn't work.
well, once I selected the date from the calenda, I hit enter key in the keyboard to select the date, the selected date appear in the DateField box, but then the calendar still visible.

thanks alot for your help.
bluemoon
Oct 14 '08 #8

NeoPa
Expert Mod 15k+
P: 31,494
Can you post all the code you have for the controls involved?
Oct 14 '08 #9

P: 56
Can you post all the code you have for the controls involved?
Yup, here is the code.
My form has a field call txtDate. I place a small cmdCal next to the txtDate field and the calendar next to the cmdCal button, but calendar is set to Visible=No (in the property). When user click on the cmdCal, Calendar is set to visible=true, then user choose a date, then hit enter, the selected date appears in the txtDate box, then I want the calendar to be invisible.

here is my code
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCal_Click()
  2. Me.Calendar.Visible = True
  3. End Sub
  4.  
  5. Private Sub txtDate_AfterUpdate()
  6. Me.Calendar.Visible = False
  7. End Sub
thanks alot!
bluemoon.

if you have any other idea, please advise. basicly, I just need to have a pull-up calendar for the date fields, that's all.
Oct 14 '08 #10

itchysf
P: 31
You could try this code, the txtbox is changed to a combobox when it is clicked on the calendar becomes visiable and the date can be selected which goes into the combobox and calendar becomes invisable. I have called the combobox (startdate), you can change that to what ever suits you.



Expand|Select|Wrap|Line Numbers
  1. Private Sub StartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.  
  3. ' Unhide the calendar and give it the focus
  4.     Calendar4.Visible = True
  5.    Calendar4.SetFocus
  6. ' Match calendar date to existing date if present or today's date
  7.     If Not IsNull(StartDate) Then
  8.        Calendar4.Value = Date
  9.     Else
  10.        Calendar4.Value = StartDate.Value
  11.     End If
  12.  
  13. End Sub
  14.  
  15. Private Sub Calendar4_Click()
  16. ' Copy chosen date from calendar to originating combo box
  17.    StartDate.Value = Calendar4.Value
  18. ' Return the focus to the combo box and hide the calendar
  19.    StartDate.SetFocus
  20.    Calendar4.Visible = False
  21.  
  22. End Sub
  23.  
Hope this helps
Oct 15 '08 #11

NeoPa
Expert Mod 15k+
P: 31,494
Try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCal_Click()
  2.     Me.Calendar.Visible = True
  3. End Sub
  4.  
  5. Private Sub Calendar_AfterUpdate()
  6.     Me.Calendar.Visible = False
  7. End Sub
Hopefully that will work. I'm not sure why your code didn't but I can't test it from here.
Oct 15 '08 #12

NeoPa
Expert Mod 15k+
P: 31,494
Also, look at Itchy's code. Although i wouldn't use the events he's used, there is some code in there that could add to the friendliness of your app. Worth nicking I would say ;)
Oct 15 '08 #13

P: 56
Thank you!

bluemoon
Oct 15 '08 #14

P: 56
You could try this code, the txtbox is changed to a combobox when it is clicked on the calendar becomes visiable and the date can be selected which goes into the combobox and calendar becomes invisable. I have called the combobox (startdate), you can change that to what ever suits you.



Expand|Select|Wrap|Line Numbers
  1. Private Sub StartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.  
  3. ' Unhide the calendar and give it the focus
  4.     Calendar4.Visible = True
  5.    Calendar4.SetFocus
  6. ' Match calendar date to existing date if present or today's date
  7.     If Not IsNull(StartDate) Then
  8.        Calendar4.Value = Date
  9.     Else
  10.        Calendar4.Value = StartDate.Value
  11.     End If
  12.  
  13. End Sub
  14.  
  15. Private Sub Calendar4_Click()
  16. ' Copy chosen date from calendar to originating combo box
  17.    StartDate.Value = Calendar4.Value
  18. ' Return the focus to the combo box and hide the calendar
  19.    StartDate.SetFocus
  20.    Calendar4.Visible = False
  21.  
  22. End Sub
  23.  
Hope this helps
Hi,
I used your code and it worked just fine. But there is only one problem left. When I click select TODAY DATE from the calenda, it gave me the date of 12/30/1899 in my Date box. And this happend only the first round. For example, if I select TODAY DATE on the calendar, it gave me the date of 12/30/1899, then I reselect, it gave me the correct date of (10/15/2008). Any idea why? I have no clue why it happended that way.

thanks!
bluemoon
Oct 15 '08 #15

itchysf
P: 31
Hi,
I used your code and it worked just fine. But there is only one problem left. When I click select TODAY DATE from the calenda, it gave me the date of 12/30/1899 in my Date box. And this happend only the first round. For example, if I select TODAY DATE on the calendar, it gave me the date of 12/30/1899, then I reselect, it gave me the correct date of (10/15/2008). Any idea why? I have no clue why it happended that way.

thanks!
bluemoon

In the properties for the calendar, check what is set for the value field(third last field under All tag). Set it to a recent date date.
Oct 16 '08 #16

Post your reply

Sign in to post your reply or Sign up for a free account.