Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Proper method for saving date picked in DTPicker (XP/SP-2)

    I have recently started using the Date and Time Picker control provided by microsoft (6.0 SP4). I like the look and feel of the control but not its behavior which I believe I have read quite a bit of bad talk about it in this forum, nevertheless, I'm using it. I was hoping someone that uses it often might be able to answer this question for me.
    I have noticed that the change event or any other event for that matter doesn't work properly after you update the control unless you refresh the form that it's on before inserting any additional code. Is this the proper method for saving what the user has picked in this control? For example...
    I have 2 of these controls that allows the user to select a starting date and ending date. If the user selects an ending date that is <= the starting date I have code that displays a msgbox and sends them back into the ending date control to retry. If I don't do a me.refresh in the Change event before any of this code it doesn't prompt the user because the control hasn't been saved with the new date. I understand this but there must be a way to save just the date they selected in the control instead of saving the entire form which the me.refresh does. This is a problem because if a user makes a change to another field and then selects a date and then decides he/she wants to cancel, the cancel doesn't work because the form has been refreshed! I hope I am explaining my problem clear enough for someone to give me some suggestions...besides telling me to just not use this control! <img src=/S/smash.gif border=0 alt=smash width=30 height=26>

    Thanks All!
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Proper method for saving date picked in DTPicker (XP/SP-2)

    Try the On Exit event. You can set its Cancel argument to True if the user selects an incorrect date:

    Private Sub dtpEndDate_Exit(Cancel As Integer)
    If Me.dtpEndDate < Me.dtpStartDate Then
    MsgBox "Ending date cannot be before starting date"
    Cancel = True
    End If
    End Sub

    This works for me without refreshing the form (Access 2002 SP-2 too.)

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proper method for saving date picked in DTPicker (XP/SP-2)

    Thanks Hans, the Exit event works perfectly! I did run into another problem that maybe you could answer? I'm also using the dtpicker on another form for the user to select a month from.
    I have adjusted the properties to:

    Format: dtpCustom
    CustomFormat: MMMM
    UpDown = True

    This way the user just sees the month's full name and can click up or down to select the previous or next month. When the form opens it displays the current month (default) which is perfect. The problem is when the control is set to invisible and then visible, the custom formatting is lost. It displays the short date format. Why is this? I have tried to set it back to show just the month by using format(me.cboMonth,"MMMM") and many other things but have been unsuccessful.

    Thanks!
    Don

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Proper method for saving date picked in DTPicker (XP/SP-2)

    I think you have run into one of the bugs of the Date/Time Picker. The negative comments you mentioned reading were not for nothing. Get around it like this:

    - Declare module-level variables sngWidth and sngHeight of type Single.
    - Instead of making the date/time picker invisible, store its dimensions and then set its width and height to 0:

    With Me.dtpEndDate
    sngWidth = .Width
    sngHeight = .Height
    .Width = 0
    .Height = 0
    End With

    - To show the control again, restore its weight and height to the original values:

    With Me.dtpEndDate
    .Width = sngWidth
    .Height = sngHeight
    End With

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proper method for saving date picked in DTPicker (XP/SP-2)

    Right on Hans! Thanks again!!!!!!

    Don

Posting Permissions

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