Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

Using DTPicker

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 21 Jan 2005 20:43 GMT
Hi,

I am currently using the value of a txtbox to set a Date Variable

Dim startDate As Date

startDate = txtStartDate.Value

startDate is then used else where in my code.

I am trying to replace the txtStartDate textbox with a DTPicker control.

I need to be able to pick both a starting date and a starting time.  When I
insert a DTPicker control the available formats are Long Date, Short Date,
Time and Custom.  If I use the Long or Short date format, then only date is
displayed and I can pick any date with a default time of 12:00:00.  If I
pick the time format I can select any time, but the date is always today's
date.  I don't know what the custom format is or how to use it.  I can't
find anyway to select both a date and a time with a single DTpicker.  Can
this be done?

As a work around, I have inserted two DTPickers.  One is formatted as short
date and the other is formatted as time.  I then build my startDate variable
using

Dim A As String
Dim B As String
Dim C As String
Dim startDate as Date

A = DTPicker1.Value 'returns "dd/mm/yy
B = Right(Format(DTPicker2.Value, "mm/dd/yy HH:mm:ss"), 8) 'returns HH:mm:ss
C = A & " " & B
startDate = C

This will produce a value for C of mm/dd/yy HH:mm:ss, which is what I need.

It seems like there should be a more straight forward way.  Can anyone offer
a suggestion.  Thanks.

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Greg Maxey - 21 Jan 2005 21:33 GMT
I think I am close to a solution.

I set the property format to custom and then in the UF initialize routing I
added:

DTPicker.CustomFormat = "MM/dd/yy HH:mm:ss:"

This rusults in the display 01/21/05 00:00:00"
I can use the arrow to set the date and then manually set the time values.

Is there a way to have both an arrow to pop up the calendar and a spinbutton
to set the hours, minutes, and seconds?

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Hi,
>
[quoted text clipped - 35 lines]
> It seems like there should be a more straight forward way.  Can
> anyone offer a suggestion.  Thanks.
Doug Robbins - 22 Jan 2005 01:14 GMT
Hi Greg,

Here's how you can use a combination of spin buttons and a list box for the
purpose of selecting things like hours, minutes and seconds:

Option Explicit
Dim i As Integer, Temp As Variant

Private Sub SpinButton1_SpinDown()
For i = 0 To ListBox1.ListCount - 1
   If ListBox1.Selected(i) Then
       If i = ListBox1.ListCount - 1 Then
           Exit Sub
       End If
       Temp = ListBox1.List(i + 1)
       ListBox1.List(i + 1) = ListBox1.List(i)
       ListBox1.List(i) = Temp
       ListBox1.ListIndex = i + 1
       Exit For
   End If
Next i

End Sub

Private Sub SpinButton1_SpinUp()
For i = 0 To ListBox1.ListCount - 1
   If ListBox1.Selected(i) Then
       If i = 0 Then
           Exit Sub
       End If
       Temp = ListBox1.List(i - 1)
       ListBox1.List(i - 1) = ListBox1.List(i)
       ListBox1.List(i) = Temp
       ListBox1.ListIndex = i - 1
       Exit For
   End If
Next i

End Sub

To load the list box (for the hours in this case) use:

Private Sub UserForm_Activate()
For i = 0 To 23
   ListBox1.AddItem  i
Next i
End Sub

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

>I think I am close to a solution.
>
[quoted text clipped - 48 lines]
>> It seems like there should be a more straight forward way.  Can
>> anyone offer a suggestion.  Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.