Results 1 to 12 of 12
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    Get Fridays Date From Combo

    Hi Guy's hope everyone is staying safe,



    What is the method of getting Fridays Date for each week selected from a combo box ?

    ie: if my Combo Box Value is 16-Nov-2020 then what is the method for retrieving 20-Nov-2020

    Same for each week selected when the combo box has changed ?

    Thank you

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    usage: getFriday([datefld])

    Code:
    
    Public Function getFriday(pvDate)
    Dim vFri
    Dim i As Integer
    i = Format(pvDate, "w")
    vFri = DateAdd("d", -(i - 6), pvDate)
    getFriday = vFri
    End Function
    


  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    The attached db (created by Pat Hartman) demonstrates many useful date functions.
    The tab labelled "First Weekday Function" may be of particular interest to you.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,980
    Nothing attached Bob?

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Welshgasman View Post
    Nothing attached Bob?
    You're quite right. That was a rather silly mistake but hopefully it' attached to this post.
    Thanks for pointing out the error
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi ranman256, thank you, where have i gone wrong here ?

    Click image for larger version. 

Name:	Capture1.JPG 
Views:	16 
Size:	26.1 KB 
ID:	43375Click image for larger version. 

Name:	Capture2.JPG 
Views:	15 
Size:	17.6 KB 
ID:	43376

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,980
    Functions normally return a value?
    So something more along the lines of
    Code:
    Me.NextFriday = GetFriday(Me.txtRemovaldate)

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by DMT Dave View Post
    Hi ranman256, thank you, where have i gone wrong here ?

    Click image for larger version. 

Name:	Capture1.JPG 
Views:	16 
Size:	26.1 KB 
ID:	43375Click image for larger version. 

Name:	Capture2.JPG 
Views:	15 
Size:	17.6 KB 
ID:	43376
    Try:
    Code:
    msgbox getFriday("04/11/2020")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,811
    If you enclose function parameters in parentheses there must be a returned value AND it must be assigned.

    Result = Msgbox("parameters", here) or
    Msgbox "parameters", here

    depending on which you need. You must also use () if you use the Call statement:

    Call (myfunction) or use

    myfunction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thank you guys much appreciated, will adjust tomorrow

  11. #11
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    you can use the weekday function to simplify your code if you wanted


    getFriday =
    DateAdd("d", -(weekday(pvdate) - 6), pvDate)

  12. #12
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thank you all for your input, all working great !

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

Similar Threads

  1. Replies: 7
    Last Post: 01-24-2018, 11:57 AM
  2. Replies: 7
    Last Post: 03-30-2015, 10:04 AM
  3. Replies: 3
    Last Post: 04-20-2014, 08:39 AM
  4. Replies: 12
    Last Post: 01-23-2014, 03:24 PM
  5. Replies: 19
    Last Post: 08-25-2011, 10:54 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