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 / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Dates with the Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
macroapa - 04 Oct 2006 14:51 GMT
I currently have the following coding:

Dim TB2 As Date
TB2 = TextBox4.Value
TextBox4.Value = Format(TB2, "dd mmmm yyyy")

This produces a date within my letters in the form 11 November 2006,
for example.

Could anybody please confirm how i can amend this date to the form 11th
November 2006.
Helmut Weber - 04 Oct 2006 17:05 GMT
Hi,

have a look at this one:

Private Sub CommandButton1_Click()
Dim sTmp1 As String
Dim sTmp2 As String
Dim TB2 As Date
TB2 = TextBox1.Value
TextBox1.Value = Format(TB2, "dd mmmm yyyy")
sTmp1 = Left(TextBox1.Value, 2)
sTmp2 = Right(TextBox1.Value, Len(TextBox1.Value) - 2)
Select Case sTmp1
Case "01", "21", "31": sTmp1 = sTmp1 & "st"
Case "02", "22": sTmp1 = sTmp1 & "nd"
Case "03", "23": sTmp1 = sTmp1 & "rd"
Case Else: sTmp1 = sTmp1 & "th"
End Select
TextBox1.Value = sTmp1 & sTmp2
End Sub

Note: I tested with textbox1,
and allowing input of a date as string
is not a good idea after all.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

 
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.