Login   ||   Register   ||   Wednesday, March 10, 2010
GET THE DATE OF CURRENT MONTH FOR THE FIRST DAY SELECTED

First off I would like to thank Bob Askew for some of this code (I cannibalized it from the Get Month Number From Month Name code he provided).

Second, you would use this either passing the full day name or an abbreviation:

MsgBox GetFirstOfDay("Wednesday")
 
Or
 
MsgBox GetFirstOfDay("Wed")
 
And if you are in June of 2009 it would return 6/3/2009

'code starts here:

Function GetFirstOfDay(pstrDay As String) As Date
    Dim strStartDay As String
    Dim strDays As String
    Dim intPos As Integer
    Dim intDay As Integer
    Dim strHold As String

    strDays = "SunMonTueWedThuFriSat"
    strHold = Left(pstrDay, 3)
    intDay = InStr(strDays, strHold)

    strStartDay = Format(DateSerial(Year(Date), Month(Date), 1), "dddd")

    If strStartDay = pstrDay Then
        GetFirstOfDay = DateSerial(Year(Date), Month(Date), 1)
    Else
        GetFirstOfDay = DateSerial(Year(Date), Month(Date), 1 + ((intDay \ 3 + 1) - 2))
    End If
End Function
 

Copyright 2007 by BTAB Development    ||   BTAB Development   ||   Terms Of Use