Consulting

Results 1 to 10 of 10

Thread: Help with datepicker control

  1. #1
    VBAX Regular
    Joined
    May 2004
    Location
    UK
    Posts
    71
    Location

    Help with datepicker control

    I have a form with a date picker on it, When you click on the date it gives you a calender type date picker but it stays on the date that it was first set up,my question is how do i get the date to default to todays date.
    I have looked at the properties of the form but there is no where that allows you to have the default day as today.

    Thanks

    Ian

  2. #2
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    You have a control?
    Did you look at the properties of the control to see the target cell?
    ~Anne Troy

  3. #3
    VBAX Regular
    Joined
    May 2004
    Location
    UK
    Posts
    71
    Location
    thanks for the reply anne
    what control?
    the target cell is ok
    when it runs after you put the date in it is ok, I supose it is not a big problem I just thought it would look better if the first date it gave you as an option was todays, as i did it in april so when you run the form it defaults to the date in april.


    Ian

  4. #4
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Ian: Date picker = Control

    What is that? A calendar?
    ~Anne Troy

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Is this a template or a workbook?
    ~Anne Troy

  6. #6
    VBAX Tutor SJ McAbney's Avatar
    Joined
    May 2004
    Location
    Glasgow
    Posts
    243
    Location
    In the form initialize event:

    Me.ctlPicker = Date()
    Where ctlpicker is the name of your Date/Time Picker control

  7. #7
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    Use:

    [VBA]DTPicker1.Value = Date[/VBA]

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  8. #8
    VBAX Regular
    Joined
    May 2004
    Location
    UK
    Posts
    71
    Location
    Thanks for everybodys help in this Is now sorted, I used the suggestion from mark also abulafia suggestion worked as well

    Private Sub DTPicker1_Enter()
    'changes picker to current date
    DTPicker1 = Date
    
    End Sub
    Regards

    Ian
    Last edited by rama4672; 06-03-2004 at 02:46 PM.

  9. #9
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    Hi Rama,

    Check out the vba tags for your code. The green and white icon

    On a technical note:
    DTPicker1 = Date
    implies:
    DTPicker1.value = Date
    as value is the default property of the datepicker object. Although not wrong it is good practice to explicitly use the property as in some scenarios it could result in errors.

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  10. #10
    Rama4672,

    Another option is the following. This is put in the calander userform.

    Private Sub UserForm_Initialize() 
    Calendar1.Year = Year(Date)
    Calendar1.Month = Month(Date)
    Calendar1.Day = Day(Date)
    End Sub

    Kurt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •