Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word MsgBox Function query: Formatting variable in 'prompt'

Status
Not open for further replies.

Magnetar

Programmer
Sep 22, 2001
73
GB
14/12/01

Hi there everyone! I have a quick query, regarding the MsgBox.

What I want to do is enable the variable as printed with the msge (prompt) to be printed in a format of my own choosing. For example, I have written a procedure which allows the user to enter a date, and then adjust that date to a future date, (using the DateAdd function, etc). I then want to print this date via the MsgBox in a given format.

What I did was to take my calculated date, and then pass it to the Format function,...and then pass THAT result to the MsgBox. However, the result is not displayed in the reqd format for some unknown reason.

Some of the code used is outlined as follows:

------------------------------------------------------

Public Sub AdjustADate()

'This macro takes the system date and adds a period of time to give a future date.

'Declare the variables:-
Dim dtToday As Date, dtAdjusted As Date, dtFormatMsgBox As Date, lResponse As Long

'ie, let 'dtToday' be the current date as entered by user;
'let 'dtAdjusted' be the future date;
'let 'dtFormatMsgBox' the future date formatted for the message box;
'let 'lResponse' be the response of the user from message box (Long integer).

'Here the user enters a date. If not, the current system date is given as default:-
dtToday = InputBox("Please Enter date.", "Set Date to be Adjusted", Format(Now(), "dd/mm/yy"))


'The future date, - generated using the'DateAdd' function:-
dtAdjusted = DateAdd("d", 15, dtToday)

'Format the calculated (adjusted) date to
'appear in in the MsgBox in format: "dd/mm/yy":-
dtFormatMsgBox = Format(dtAdjusted, "d mmmm yyyy")

'Here the user is asked to confirm whether he/she
'wants to use the date calculated:
lResponse = MsgBox("The due date calculated is: " & dtFormatMsgBox & ". Do you want to use it? ", _
vbQuestion + vbYesNo, "Date Confirmation")
.
.
.
.(etc)
--------------------------------------------------------

From above it is the 'dtFormatMsgBox' variable within the 'prompt' part of the MsgBox function which I hoped would display the date in the reqd format, as set up in:

"dtFormatMsgBox = Format(dtAdjusted, "d mmmm yyyy")".

This should be very easy to implement, but somehow I am still obtaining the result in the MsgBox from the 'dtAdjusted' variable!

Any suggestions/tips/advice (or even an 'It can't be done!..') would be greatly appreciated, please.


Many ThanX !

Magnetar :-I
 
To preserve the format, dtFormatMsgBox should be declared as a string, not date.

Dim dtFormatMsgBox as String Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top