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 / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

InputBox requesting dates between two predefined dates

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barb Reinhardt - 20 Jan 2006 16:31 GMT
I'm trying to figure out how to display this programmatically for the user.  
I want the user to enter a date between the following two dates:

Date 1 is defined as SummaryMin
Date 2 is defined named variable CPI_SPI_PITD_LastMo

I want them to enter the date they want to use (or select one of the two).  
How would y'all approach this.

Thanks in advance,
Barb Reinhardt
Toppers - 20 Jan 2006 19:57 GMT
Barb,
             Perhaps something along these lines. For this example, I set
SummaryMin as the default date.

Sub InForm()

Dim SummaryMin As Date, CPI_SPI_PITD_LastMo As Date, GetDate as Date

SummaryMin = "01/01/2006"
CPI_SPI_PITD_LastMo = "31/01/2006"

Do
getDate = DateValue(Application.InputBox("Enter Date between " & SummaryMin
& " and " & CPI_SPI_PITD_LastMo, "Title date ", SummaryMin, Type:=2))
If getDate = "False" Then Exit Sub  ' Cancel
If Not Application.And(getDate >= SummaryMin, getDate <=
CPI_SPI_PITD_LastMo) Then
  MsgBox "Invalid date. Please re-enter"
End If
Loop Until Application.And(getDate >= SummaryMin, getDate <=
CPI_SPI_PITD_LastMo)
End Sub

> I'm trying to figure out how to display this programmatically for the user.  
> I want the user to enter a date between the following two dates:
[quoted text clipped - 7 lines]
> Thanks in advance,
> Barb Reinhardt
JE McGimpsey - 20 Jan 2006 21:45 GMT
One way:

(Your post is a bit confusing - do you want to "enter a date between the
following two dates", or "select one of the two"? I assumed the former:

   Const SummaryMin = #1/1/2006#
   Const CPI_SPI_PITD_LastMo = #12/31/2006#
   Dim vResult As Variant
   Dim dtFirst As Date
   Dim dtLast As Date
   dtFirst = SummaryMin
   dtLast = CPI_SPI_PITD_LastMo
   Do
       vResult = Application.InputBox( _
                   Prompt:="Enter a date between " & dtFirst & _
                           " and " & dtLast & ":", _
                   Title:="Enter Date", _
                   Default:=dtFirst, _
                   Type:=1)
       If vResult = False Then Exit Sub 'user cancelled
       vResult = vResult - ActiveWorkbook.Date1904 * 1462
   Loop Until (vResult >= dtFirst) And (vResult <= dtLast)
   'Rest of macro
   MsgBox "Valid date!"

> I'm trying to figure out how to display this programmatically for the user.  
> I want the user to enter a date between the following two dates:
[quoted text clipped - 7 lines]
> Thanks in advance,
> Barb Reinhardt
 
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.