DTPicker misbehavin - badly.

jag108

Active Member
Joined
May 14, 2002
Messages
433
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
I am trying to run SQL from a user form. I have the SQL running prefectly, but when I try to use a form with two DTPickers I start running into trouble.

I want to format the dates in the DTPickers as,
DTPicker1.customformat = Format(now(), "yyyymmdd")
I need this date format because it is the format in the Oracle DB we use.
Once the Form initialises, it runs the code above. Then the problem starts if you want to adjust the date using the DTPicker. Quite simply it will not let you, it will drop down showing dates etc, but no matter what you do it will only use the initialised Now() date!!!!

Is this a bug or is there another way of me formatting a DTPicker at start up?

Thanks in advance.
Jag
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

pfarmer

Well-known Member
Joined
Jul 6, 2005
Messages
550
jag108 said:
I am trying to run SQL from a user form. I have the SQL running prefectly, but when I try to use a form with two DTPickers I start running into trouble.

I want to format the dates in the DTPickers as,
DTPicker1.customformat = Format(now(), "yyyymmdd")
I need this date format because it is the format in the Oracle DB we use.
Once the Form initialises, it runs the code above. Then the problem starts if you want to adjust the date using the DTPicker. Quite simply it will not let you, it will drop down showing dates etc, but no matter what you do it will only use the initialised Now() date!!!!

Is this a bug or is there another way of me formatting a DTPicker at start up?

Thanks in advance.
Jag

Why not format the value the date picker provides you rather then trying to format the datepicker itself?

Perry
 
Upvote 0

pfarmer

Well-known Member
Joined
Jul 6, 2005
Messages
550
jag108 said:
I am trying to run SQL from a user form. I have the SQL running prefectly, but when I try to use a form with two DTPickers I start running into trouble.

I want to format the dates in the DTPickers as,
DTPicker1.customformat = Format(now(), "yyyymmdd")
I need this date format because it is the format in the Oracle DB we use.
Once the Form initialises, it runs the code above. Then the problem starts if you want to adjust the date using the DTPicker. Quite simply it will not let you, it will drop down showing dates etc, but no matter what you do it will only use the initialised Now() date!!!!

Is this a bug or is there another way of me formatting a DTPicker at start up?

Thanks in advance.
Jag


Jag,

I use four pickers to pick start and stop dates and times. The basic format I use is:

DTPicker1.Value = Now()

DTPicker2.Value = Now()

DTPicker3.CustomFormat = "HHmm"
DTPicker3.Hour = 7
DTPicker4.CustomFormat = "HHmm"
DTPicker4.Hour = 15

DTPicker3.Minute = 0
DTPicker4.Minute = 30

For pickers one and two I set the properties to dtpshortdate to yield something like 8/24/2005. Pickers three and four are used to pick the hours and I format those as indicated above. In the properites they indicate HHmm without the quotes. They default to a start of 0700 and a stop time of 1530.

Now I also have an easter egg of sorts, if you click a lable on the form it will place the current date in picker one and the current time in picker three.

It will also adjust the ending time to be 10 minutes from the start time as a default if later then 1530 using the following code:

Code:
Private Sub Label16_Click()

Dim DaysDiff
Dim HoursDiff
Dim MinutesDiff
Dim JobLengthHours
Dim x
Dim y

On Error GoTo none

DTPicker1.Value = Now()
DTPicker2.MinDate = DTPicker1.Value
DTPicker3.Value = Now()

DaysDiff = DateDiff("d", DTPicker1.Value, DTPicker2.Value)
HoursDiff = DTPicker4.Hour - DTPicker3.Hour

MinutesDiff = DTPicker4.Minute - DTPicker3.Minute
MinutesDiff = MinutesDiff / 60
MinutesDiff = Format(MinutesDiff, "##0.##")

Label62.Caption = DaysDiff * 24 + HoursDiff + MinutesDiff & " Hours"


If DaysDiff * 24 + HoursDiff + MinutesDiff <= 0.17 Then
x = DTPicker3.Minute + 10
y = DTPicker3.Hour
If x > 59 Then
x = x - 60

y = DTPicker3.Hour + 1
End If
If y > 23 Then
y = y - 24

DTPicker2.Value = DTPicker1.Value + 1

End If
DTPicker4.Minute = x
DTPicker4.Hour = y
End If

DaysDiff = DateDiff("d", DTPicker1.Value, DTPicker2.Value)
HoursDiff = DTPicker4.Hour - DTPicker3.Hour

MinutesDiff = DTPicker4.Minute - DTPicker3.Minute
MinutesDiff = MinutesDiff / 60
MinutesDiff = Format(MinutesDiff, "##0.##")

Label62.Caption = DaysDiff * 24 + HoursDiff + MinutesDiff & " Hours"

none:

End Sub

Note that it adjust for going past midnight.

I know that this code doesn't really pertain to you but I included it to show the various options you can use via VBA to input values into a picker. Also I am sure it can be improved upon but heh, it works as is.

Perry
 
Upvote 0

Forum statistics

Threads
1,196,027
Messages
6,012,950
Members
441,740
Latest member
abaz21

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top