Dates with the Macro

M

macroapa

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.
 
H

Helmut Weber

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.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top