Plant this code in a standard code module. Place your mouse cursor
inside of someSub(). Press the F5 key. This will display the given day
which the built-in Date() function returns and if it is the 1st, 2nd,
3rd... occurence of that day in that month. You can use any date value
for the argument.
'------------------------------------------------------
Sub someSub()
Dim d1 As Date, arrSuffix As Variant
arrSuffix = Array("", "1st", "2nd", "3rd", "4th", "5th")
d1 = Date '--d1 can be any date you want: d1=#3/13/06#
Debug.Print arrSuffix(DayOf MonthCount(d1)) & " " & _
WeekdayName(Wee kday(d1))
End Sub
Function DayOfMonthCount (d1 As Date) As Integer
Dim i As Integer, j As Integer, k As Integer, d2 As Date
d2 = d1 - Day(d1) + 1 '--go to beginning of d1
k = 0
'--get count of days in the month of d1
j = Day(DateAdd("m" , 1, d1) - Day(DateAdd("m" , 1, d1)))
For i = 0 To j
'--get count of times the d1 day occurs in the month of d1
If Weekday(d2 + i) = Weekday(d1) Then k = k + 1
If d2 + i > d1 Then Exit For
Next
DayOfMonthCount = k
End Function
'----------------------------------------------------
Rich
*** Sent via Developersdex
http://www.developersdex.com ***