Results 1 to 5 of 5
  1. #1
    bcn1988 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2012
    Posts
    7

    Parameter Value = Monday of the current week VBA

    Hello!



    I have developed a VBA procedure to export a number of queries as a text (comma delimitted) to a specific folder. However, I have ran into a snag as one of the queries requires the user to input the date of the Monday of the current week. For example, if we use the current week we are in (09/09/2013 - 09/13/2013: 5 day business week). Let's say the user runs the code on Monday, 09/09/2013. Then the user needs to input two parameters in two seperate instances, one after the other. First they would enter the month: "09". Then they would enter the day: "09". After they input these two parameters, the query will run. If the user runs the report on a Tuesday (date in this instance would be 09/10/2013), then I still need the two parameters to be, Month: "09", Day: "09". This holds true if the query is ran on a Wednesday (parameters still would be 09/09). The code I current have works great for queries that do not need users to enter a parameter, and the current code is the following:

    Code:
     Sub Export_Queries()
    
    Dim OutputPath As String
    Dim strQryName1 As String
    Dim strXLFile1 As String
    
    
    OutputPath = "C:\"
    strQryName1 = "Query1"
    strXLFile1 = OutputPath & "Query1" & ".txt"
    
    
    DoCmd.TransferText acExportDelim, "Query1_Export", strQryName1, strXLFile1, True
    
    
    End Sub
    What I need is the following:
    * Code that will input the correct parameter dates for the Monday of the current week (please see explanation above).
    * The code needs to be implemented in the code I have above.

    Please let me know if you need any additional information! Thank you for all of your help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    DateAdd("d",-weekday(Date(),3),Date())

    or

    DateAdd("d",-weekday(Date())+2,Date())
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mrojas is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Location
    Concord California
    Posts
    72
    You might need a form to allow the user to enter the required input. Then validate the input using a Select Case structure and run query based on case results using the DateAdd function June7 suggested; except that you'll have to add one case for each day of the week other than Monday.

  4. #4
    bcn1988 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2012
    Posts
    7
    Hey June7,

    Thanks for replying with a formula. I tested the formulas and both of them are returning Monday's date. However, which of the formulas should I depend on more to return the current Monday of the current week's date?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    I think either works as well as the other.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. How to sort Day of week from Monday to Saturday
    By ultra5219 in forum Queries
    Replies: 3
    Last Post: 02-20-2013, 06:52 AM
  2. Start a report on week 40 of a week count
    By aspitalnick in forum Reports
    Replies: 8
    Last Post: 11-28-2012, 04:53 PM
  3. Replies: 4
    Last Post: 01-23-2012, 08:21 AM
  4. Parameter Date - Force a Monday Date
    By ker9 in forum Queries
    Replies: 3
    Last Post: 07-26-2011, 01:06 PM
  5. Replies: 1
    Last Post: 07-27-2010, 09:47 AM

Tags for this Thread

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