MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Display date on useform...

Posted by newbie on August 02, 2001 2:07 AM

Hello again..

I have succeed doing this..the problem is the date format and the time format..but problem occured again...

1. when i use "dd mmm yyyy format" , it still display as "m d yy" ( i want it to look like this 02 July 2001 but it show 7/2/01 )

2. how can i display time without date i.e
i want it show like this : 4:54:45 PM and not like : 8/2/01 4:54:45 PM

3. is it possible to add text after the date..i.e..
" 02 july 2001 4:54:45 PM - NiuB like you "

the conclusion can i display all this thing to be display as the format that i like.. i.e :
" 02 July 2001 4:54:45 PM - NiuB like you "

I meant using single text box only instead like what am i doing right now using two text boxes and still can't get the result

thanks a zillion

here is my code..

Private Sub UserForm_activate()

TextBox1.Value = "The time is now : " & Now
TextBox2.Value = "Todays date is : " & Date

TextBox1.Value = Format(TextBox1.Value, "hh:mm AM/PM ")
TextBox2.Value = Format(TextBox2.Value, "dd mmmm yyyy ")

End Sub

Posted by Cory on August 02, 2001 9:32 AM

Unfortunately, you can't use the format function along with text in the same textbox. An alternative would be to use separate labels (or textboxs) for each piece. Labels by default dont display anything but what you put in them (no special effects like borders or backcolors). In the following example I used 4 labels in a line to make them appear as one sentence when the form is run:

Private Sub UserForm_Activate()
Label1.Caption = "Todays date and time are: "
Label2.Caption = Date
Label2.Caption = Format(Label2.Caption, "dd-mmmm-yyyy")
Label3.Caption = Now
Label3.Caption = Format(Label3.Caption, "hh:mm AMPM")
Label4.Caption = " -NiuB like you."
End Sub

This gave me a form with the sentence:

Today's date and time are: 02-August-2001 11:35 AM -NiuB like you.

Probably not what you're looking for, but produces the same results nonetheless...