Results 1 to 5 of 5
  1. #1
    Markb384 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    44

    Show Date Picker on Load and Verifying Date

    Hi guys

    I use the following command to show the date picker when a textbox gets focus, which works pretty well.

    Code:
    Private Sub date_select_GotFocus()'sub to show the date picker automatically when the date cell is selected
        RunCommand acCmdShowDatePicker
    End Sub
    However, the textbox is also the first textbox on the form and hence gets focus on form load, meaning the focus needs to be lost before my above code will run. Ideally, I'd like nothing on the form to have focus on loading, but a quick Google makes me think this is impossible. So I tried to add the following to my form_load() routine but it isn't working, i.e. the datepicker doesn't show (although the focus appears to be set as the little icon appears adjacent to the textbox). Prior to the sample below, the code goes through all of the controls on the form and resets them but I don't think this should impact on the code.



    Code:
    'set the calendar visible for the date select
        date_select.SetFocus
        RunCommand acCmdShowDatePicker
    Does anyone have any ideas what is going on here? Have I missed something simple?

    Additionally, I need to confirm that the user can only enter a date as I use the entered date further on in some VBA. I could try and catch this later in the VBA code but I would prefer to nip the problem in the bud and force the user to only enter a date. Ideally, if I could actually disable keypresses that would be probably perfect, forcing the user to only select dates using the datepicker, but I'm not entirely sure if this is the most effective way, nor how to go about doing it. Anyone got any clues on this for me please?

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    If you are running access 2010, the date picker is auto on textbox. You just need to set property "Format" to any of the date type (Long Date, Medium Date, Short Date, etc). Then the textbox will have a date picker icon (top right corner) when you are in the text box.

    No code needed.

  3. #3
    Markb384 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    44
    Hi lfpm062010, I have it already set so that the icon appears. What I want (and what my code currently does) it to show the actual calendar (as if you had clicked the icon) automatically.

  4. #4
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402
    try in form open

    docmd.gotocontrol acform, "your form name here"
    RunCommand acCmdShowDatePicker

    to start on that field.


    Also I don't know if the Access2010 calender control is the same as setting the dropdown action on a combobox but that or something like it may work.

  5. #5
    Markb384 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    44
    Hi Trevor

    What I use your suggestion, it crashes and says it expects an array. I have kind of solved the problem by rearranging my form slightly though such that the first textbox isn't the date select textbox though.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Date picker
    By Nayana in forum Access
    Replies: 4
    Last Post: 12-19-2013, 06:10 AM
  2. Date criteria using between and form date picker
    By killermonkey in forum Queries
    Replies: 3
    Last Post: 03-21-2013, 12:44 PM
  3. Date Picker?
    By gazzieh in forum Forms
    Replies: 9
    Last Post: 02-09-2013, 09:35 AM
  4. Another date picker.
    By Rod in forum Code Repository
    Replies: 1
    Last Post: 11-05-2012, 07:53 PM
  5. Date picker
    By SFC in forum Forms
    Replies: 2
    Last Post: 02-07-2012, 04:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums