Results 1 to 6 of 6
  1. #1
    dweekley is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    May 2010
    Posts
    52

    First Weds of Month...

    I am having trouble creating criteria. We have company meeting the first Weds of each month. I am trying to only display lets say First Weds. of June thru the First Thurs. of May. This would ofcourse roll on to July thru June once the June date passes.



    Any help would be greatly appreciated.
    Thanks
    David

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    The Following Function will calculate the first Wednesday of the current Month of the Year:

    Function FirstWedOfMonth() As Date
    For x = 0 To 6
    If Weekday(DateSerial(Year(Date), Month(Date), 1) + x, vbUseSystemDayOfWeek) = vbWednesday Then
    FirstWedOfMonth = DateSerial(Year(Date), Month(Date), 1) + x
    End If
    Next x
    End Function


    if you want to specify a date and want to calculate the First Wednesday for that Month of the Year use this code:

    Option Compare Database
    Dim MyDate As Date
    Function FirstWedOfMonth(MyDate) As Date
    If IsNull(MyDate) Then
    Exit Function
    Else
    For x = 0 To 6
    If Weekday(DateSerial(Year(MyDate), Month(MyDate), 1) + x, vbUseSystemDayOfWeek) = vbWednesday Then
    FirstWedOfMonth = DateSerial(Year(MyDate), Month(MyDate), 1) + x
    End If
    Next x
    End If
    End Function

  3. #3
    dweekley is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    May 2010
    Posts
    52
    Thanks for the quick response. When I mentioned criteria, I will be only running this in the form of a query. Not sure if that script can run in a query?

    David

  4. #4
    Join Date
    May 2010
    Posts
    339
    Quote Originally Posted by dweekley View Post
    Thanks for the quick response. When I mentioned criteria, I will be only running this in the form of a query. Not sure if that script can run in a query?

    David
    You paste the code maximus gave you into a new function. Then create a new query that calls the function's name, in this case.

    Code:
    FirstWedOfMonth
    Also be careful what you name the query, dont use the same name as the function.

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Thanks Access_Blaster!!!!.

  6. #6
    Join Date
    May 2010
    Posts
    339
    You are welcome.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to group by month
    By okrobie in forum Queries
    Replies: 4
    Last Post: 06-09-2011, 04:41 AM
  2. month function..
    By thewabit in forum Programming
    Replies: 13
    Last Post: 04-19-2010, 10:01 PM
  3. by year by month
    By nkuebelbeck in forum Reports
    Replies: 21
    Last Post: 03-24-2010, 01:53 PM
  4. SQL Query by day to end of month
    By tcasey in forum Queries
    Replies: 0
    Last Post: 10-07-2008, 09:55 PM
  5. Total no of days in a month
    By wasim_sono in forum Forms
    Replies: 4
    Last Post: 10-15-2006, 01:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums