Results 1 to 4 of 4
  1. #1
    School Boy Error is offline Advanced Beginner
    Windows 7 32bit Access 2013 64bit
    Join Date
    Oct 2012
    Posts
    72

    Formula to specify start date

    Hello, I'm completely new to this so could you tell me if it is possible to specify the start date in a form depending on the current date? E.g. if it's between 1st September and Decem1ber I would like the start date to be 1st SeptemberIf it's between 1st January and 30th April I would like the start date to be 1st January If it's between 1st May and 31st August I would like the start date to be 1st MayIs this possible?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Do you think you could write a Select Case statement that would return the date you want?

  3. #3
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    place this code into a module, (Alt-F11, insert, modules), save
    then you can use it in a query or form
    usage:

    SetStartDte([dateFld])
    or
    SetStartDte(date())

    Code:
         
    Public function SetStartDte(ByVal pvDate)
    dim vMo, vYr
    
    if isNull(pvDate) then exit function
    vMo = month(pvDate)
    vyr = year(pvDate)
    
    
    Select Case vMo
        Case 1,2,3,4
           vDate = "1/1/" & vYr
    
        Case 5,6,8,7
           vDate = "5/1/" & vYr
    
        Case 9,10,11,12
           vDate = "9/1/" & vYr
    End Select
    
    SetStartDte=vDate
    End function

  4. #4
    School Boy Error is offline Advanced Beginner
    Windows 7 32bit Access 2013 64bit
    Join Date
    Oct 2012
    Posts
    72
    Legend!I had to tweak slightly to:
    Code:
    Public Function SetStartDte(ByVal pvDate)Dim vMo, vYrIf IsNull(pvDate) Then Exit FunctionvMo = Month(pvDate)vYr = Year(pvDate)Select Case vMo    Case 1, 2, 3, 4       vDate = "01/01/" & vYr    Case 5, 6, 8, 7       vDate = "01/05/" & vYr    Case 9, 10, 11, 12       vDate = "01/09/" & vYrEnd SelectSetStartDte = vDateEnd Function
    But seems to be working a treat, many thanks!

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

Similar Threads

  1. Replies: 4
    Last Post: 11-20-2018, 11:57 PM
  2. Replies: 6
    Last Post: 03-02-2016, 12:58 PM
  3. Replies: 3
    Last Post: 02-16-2016, 05:02 PM
  4. Replies: 5
    Last Post: 09-02-2015, 11:39 AM
  5. Replies: 15
    Last Post: 04-06-2012, 10:57 AM

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