Results 1 to 4 of 4

Formula to specify start date

  1. #1
    School Boy Error is offline Advanced Beginner
    Windows 7 32bit Access 2013 64bit
    Join Date
    Oct 2012
    Posts
    52

    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,664
    Do you think you could write a Select Case statement that would return the date you want?
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    5,714
    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
    52
    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: 6
    Last Post: 03-02-2016, 11:58 AM
  2. Replies: 3
    Last Post: 02-16-2016, 04:02 PM
  3. Replies: 5
    Last Post: 09-02-2015, 10:39 AM
  4. Replies: 3
    Last Post: 08-18-2015, 10:32 PM
  5. Replies: 15
    Last Post: 04-06-2012, 09: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
  •  
Tech Forums: Microsoft Office Forums