Calculate change of date in inputbox 
Author Message
 Calculate change of date in inputbox

Hi,

I'm trying to create an input box that has today's date by
default already displayed in full and highlighted,
eg "Wednesday 25 March 2003", and then the user can just
type in -1 (or any other neg number) and press OK for the
date to be displayed backdated, ie, if -1 is typed in and
okayed, the date "Tuesday 24 March 2003" would come out in
the document. I know it's something to do with
FormatDateTime and DateDiff but I'm not getting anywhere!

Could anyone help?

Thanks

Siobhan



Sat, 01 Oct 2005 23:29:03 GMT  
 Calculate change of date in inputbox
Hi Siobahn,

I think  you can use something like the following:

Dim dDate
Dim iDifference As Integer
dDate = Format(Now, "dddd d mmmm yyyy")

iDifference = InputBox("To subtract days, enter a negative number
(e.g., -1, -2).", _
    Title:="Create Date", Default:=dDate)

dDate = Format(DateAdd("d", iDifference, Date), "dddd d mmmm yyyy")

MsgBox dDate

HTH


Quote:
> Hi,

> I'm trying to create an input box that has today's date by
> default already displayed in full and highlighted,
> eg "Wednesday 25 March 2003", and then the user can just
> type in -1 (or any other neg number) and press OK for the
> date to be displayed backdated, ie, if -1 is typed in and
> okayed, the date "Tuesday 24 March 2003" would come out in
> the document. I know it's something to do with
> FormatDateTime and DateDiff but I'm not getting anywhere!

> Could anyone help?

> Thanks

> Siobhan



Sat, 01 Oct 2005 23:59:03 GMT  
 Calculate change of date in inputbox
Dear Dave,

Thank you very much - it works a treat! I've spent HOURS
trying to work that out!!!

Thanks again

Siobhan

Quote:
>-----Original Message-----
>Hi Siobahn,

>I think  you can use something like the following:

>Dim dDate
>Dim iDifference As Integer
>dDate = Format(Now, "dddd d mmmm yyyy")

>iDifference = InputBox("To subtract days, enter a
negative number
>(e.g., -1, -2).", _
>    Title:="Create Date", Default:=dDate)

>dDate = Format(DateAdd("d", iDifference, Date), "dddd d
mmmm yyyy")

>MsgBox dDate

>HTH



>> Hi,

>> I'm trying to create an input box that has today's date
by
>> default already displayed in full and highlighted,
>> eg "Wednesday 25 March 2003", and then the user can just
>> type in -1 (or any other neg number) and press OK for
the
>> date to be displayed backdated, ie, if -1 is typed in
and
>> okayed, the date "Tuesday 24 March 2003" would come out
in
>> the document. I know it's something to do with
>> FormatDateTime and DateDiff but I'm not getting
anywhere!

>> Could anyone help?

>> Thanks

>> Siobhan

>.



Sun, 02 Oct 2005 00:13:30 GMT  
 Calculate change of date in inputbox
Hello Dave,

Sorry to be a pest, but could you tell me how to print out
the default date (today's date) if no neg number is
inputted into the box, but the enter button is pressed
instead? I've tried setting up another variable with
today's date and using if.then.else to replace it, but VBA
just won't have it!!! I get 'type mismatch' and the
idifference line is highlighted.

Thanks,

Siobhan

Quote:
>-----Original Message-----
>Hi Siobahn,

>I think  you can use something like the following:

>Dim dDate
>Dim iDifference As Integer
>dDate = Format(Now, "dddd d mmmm yyyy")

>iDifference = InputBox("To subtract days, enter a
negative number
>(e.g., -1, -2).", _
>    Title:="Create Date", Default:=dDate)

>dDate = Format(DateAdd("d", iDifference, Date), "dddd d
mmmm yyyy")

>MsgBox dDate

>HTH



>> Hi,

>> I'm trying to create an input box that has today's date
by
>> default already displayed in full and highlighted,
>> eg "Wednesday 25 March 2003", and then the user can just
>> type in -1 (or any other neg number) and press OK for
the
>> date to be displayed backdated, ie, if -1 is typed in
and
>> okayed, the date "Tuesday 24 March 2003" would come out
in
>> the document. I know it's something to do with
>> FormatDateTime and DateDiff but I'm not getting
anywhere!

>> Could anyone help?

>> Thanks

>> Siobhan

>.



Wed, 05 Oct 2005 22:53:27 GMT  
 Calculate change of date in inputbox
Hi Siobahn

I've modified Dave's code slightly. If you click the OK button without
altering the default date displayed by the input box then it uses todays
date:

Public Sub DateInput()
    Dim dDate
    Dim varDifference As Variant

    dDate = Format(Date, "dddd d mmmm yyyy")

    varDifference = InputBox("To subtract days, " & _
      "enter a negative number (e.g., -1, -2).", _
        Title:="Create Date", Default:=dDate)

    ' If the users just clicked OK then the inputs not
    ' going to be numeric as the defaults a date
    If IsNumeric(varDifference) Then
        dDate = Format(DateAdd("d", varDifference, Date), _
          "dddd d mmmm yyyy")
    End If

    MsgBox dDate
End Sub

I hope this helps + Cheers - Peter



Quote:
> Hello Dave,

> Sorry to be a pest, but could you tell me how to print out
> the default date (today's date) if no neg number is
> inputted into the box, but the enter button is pressed
> instead? I've tried setting up another variable with
> today's date and using if.then.else to replace it, but VBA
> just won't have it!!! I get 'type mismatch' and the
> idifference line is highlighted.

> Thanks,

> Siobhan

>>-----Original Message-----
>>Hi Siobahn,

>>I think  you can use something like the following:

>>Dim dDate
>>Dim iDifference As Integer
>>dDate = Format(Now, "dddd d mmmm yyyy")

>>iDifference = InputBox("To subtract days, enter a
> negative number
>>(e.g., -1, -2).", _
>>    Title:="Create Date", Default:=dDate)

>>dDate = Format(DateAdd("d", iDifference, Date), "dddd d
> mmmm yyyy")

>>MsgBox dDate

>>HTH



>>> Hi,

>>> I'm trying to create an input box that has today's date
> by
>>> default already displayed in full and highlighted,
>>> eg "Wednesday 25 March 2003", and then the user can just
>>> type in -1 (or any other neg number) and press OK for
> the
>>> date to be displayed backdated, ie, if -1 is typed in
> and
>>> okayed, the date "Tuesday 24 March 2003" would come out
> in
>>> the document. I know it's something to do with
>>> FormatDateTime and DateDiff but I'm not getting
> anywhere!

>>> Could anyone help?

>>> Thanks

>>> Siobhan

>>.



Thu, 06 Oct 2005 08:01:31 GMT  
 Calculate change of date in inputbox
Dear Peter,

Thank you vv much - it's perfect!!! I was so close but
going in biiigg circles!

Thanks again,

Siobhan

Quote:
>-----Original Message-----
>Hi Siobahn

>I've modified Dave's code slightly. If you click the OK
button without
>altering the default date displayed by the input box then
it uses todays
>date:

>Public Sub DateInput()
>    Dim dDate
>    Dim varDifference As Variant

>    dDate = Format(Date, "dddd d mmmm yyyy")

>    varDifference = InputBox("To subtract days, " & _
>      "enter a negative number (e.g., -1, -2).", _
>        Title:="Create Date", Default:=dDate)

>    ' If the users just clicked OK then the inputs not
>    ' going to be numeric as the defaults a date
>    If IsNumeric(varDifference) Then
>        dDate = Format(DateAdd("d", varDifference, Date),
_
>          "dddd d mmmm yyyy")
>    End If

>    MsgBox dDate
>End Sub

>I hope this helps + Cheers - Peter




- Show quoted text -

Quote:

>> Hello Dave,

>> Sorry to be a pest, but could you tell me how to print
out
>> the default date (today's date) if no neg number is
>> inputted into the box, but the enter button is pressed
>> instead? I've tried setting up another variable with
>> today's date and using if.then.else to replace it, but
VBA
>> just won't have it!!! I get 'type mismatch' and the
>> idifference line is highlighted.

>> Thanks,

>> Siobhan

>>>-----Original Message-----
>>>Hi Siobahn,

>>>I think  you can use something like the following:

>>>Dim dDate
>>>Dim iDifference As Integer
>>>dDate = Format(Now, "dddd d mmmm yyyy")

>>>iDifference = InputBox("To subtract days, enter a
>> negative number
>>>(e.g., -1, -2).", _
>>>    Title:="Create Date", Default:=dDate)

>>>dDate = Format(DateAdd("d", iDifference, Date), "dddd d
>> mmmm yyyy")

>>>MsgBox dDate

>>>HTH



>>>> Hi,

>>>> I'm trying to create an input box that has today's
date
>> by
>>>> default already displayed in full and highlighted,
>>>> eg "Wednesday 25 March 2003", and then the user can
just
>>>> type in -1 (or any other neg number) and press OK for
>> the
>>>> date to be displayed backdated, ie, if -1 is typed in
>> and
>>>> okayed, the date "Tuesday 24 March 2003" would come
out
>> in
>>>> the document. I know it's something to do with
>>>> FormatDateTime and DateDiff but I'm not getting
>> anywhere!

>>>> Could anyone help?

>>>> Thanks

>>>> Siobhan

>>>.

>.



Sun, 09 Oct 2005 22:57:08 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Changing a Calculate field (Date) depending on Current date

2. calculate dates calculate time

3. Date/Time picker and calculating date differences

4. Calculating future date from date function

5. Date mask for InputBox??

6. InputBox vs. InputBox$

7. Q: Change Font-size in Inputbox ??

8. Calculate no of days in a month within a specified date range

9. Calculate Date Range From Prior Week

10. Calculating Age using date selected by User

11. Updating Calculated field depending on Current Date

12. Calculating date interval - for working days

 

 
Powered by phpBB® Forum Software