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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date format

Status
Not open for further replies.

Dwight3238

Technical User
Aug 19, 2003
11
US
i'm writing some VBA code for Word and in a text box in a userform i'm getting the user to input the date in the mm/dd/yyyy format, though that's just verbal instructions i don't know how to control that input.

my issue is that i need to convert that date to the "mmmm dd, yyyy" format in my code. i have tried to use the following but it doesn't seem to work
dim myDate as Date, txtDate as Date
myDate = Format(txtDate, "mmmm dd, yyyy")

txtDate is from the text box.

i would appreaciate some guidance on how to first verfiy the input into the text box then how to convert the format.

Thanks
Dwight
 
Okay, here's what I did:

Code:
Private Sub TextBox1_LostFocus()
Dim myDate as String
myDate = Format(TextBox1, "mmmm dd, yyyy")
TextBox1 = myDate
End Sub

I put the code in the Lost Focus and after the format was complete, I assigned the format variable back to the text box. Also, the mmmm corresponds to a full month tag (11=November) which is a string. The Dim's should be as String, not as date.

Hope that helps.


DreamerZ
simplesolutions@prodigy.net
[ignore][/ignore]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top