Results 1 to 2 of 2
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Textbox value (WinNT/Word97)

    Can anyone tell me if it is possible to use date ordinals in VBA?

    I have a userform*, one of the boxes of which needs to have today's date, with ordinal, as the default entry - eg 19th March 2003 - and I can't find any way of making it do this.

    We have an autotext entry which does this - {date @ "d" * ordinal} {date @ "MMMM"} {date @ "yyyy"} - but I can't find a way to put the *result* of this into the text box, either - it just puts the code in, as typed out above!

    Any help would be greatly appreciated!

    * PS this is a completely separate project from the other one (for a start, it's in Word, not XL) in case you've been following my other post!
    Beryl M


  2. #2
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Textbox value (WinNT/Word97)

    Found the answer myself - or at least, *an* answer! Used the following:
    <pre>Private Sub UserForm_Initialize()
    dim dayNum as string
    daynum = Day(Date)
    txtdateLine.Value = daynum + ordinal(Day(Date)) + Format(Date, " MMMM yyyy")
    End Sub
    _
    Private Function ordinal(num As Integer) As String
    If (num 10) Mod 10 = 1 Then
    ordinal = "th"
    Else
    Select Case num Mod 10
    Case 1
    ordinal = "st"
    Case 2
    ordinal = "nd"
    Case 3
    ordinal = "rd"
    Case Else
    ordinal = "th"
    End Select
    End If
    End Function
    </pre>

    Just thought I'd post it in case anyone else finds it useful!
    Beryl M


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •