dcsimg
Results 1 to 3 of 3

Thread: fill day of month in column in access table based 02-2018

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,797

    fill day of month in column in access table based 02-2018

    I just have a a variable MyMonth as string "02-2018"

    Ho to fill column/field named DAYS in access table named MONTH

    To the end of code:
    01/08/2018
    02/08/2018
    03/08/2018
    04/08/2018
    05/08/2018
    ...
    31/08/2018

    ???

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,332

    Re: fill day of month in column in access table based 02-2018

    Throw away MyMonth.

    Replace it with a Date variable FirstDate containing #2/1/2018# instead.

    Then you can use DateAdd() to add 1 month to FirstDate, and again to subtract one day from that giving LastDate.

    Then just loop from FirstDate to LastDate:

    Code:
        Dim FirstDate As Date
        Dim LastDate As Date
        Dim EachDate As Date
    
        FirstDate = #2/1/2018#
        LastDate = DateAdd("d", -1, DateAdd("m", 1, FirstDate))
        For EachDate = FirstDate To LastDate
            Debug.Print EachDate
            'Or insert EachDate rows into MONTH table.
        Next
    This assumes your weird "02-2018" was February 2018.
    Last edited by dilettante; Nov 10th, 2018 at 04:09 PM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,797

    Re: fill day of month in column in access table based 02-2018

    Quote Originally Posted by dilettante View Post
    Throw away MyMonth.

    Replace it with a Date variable FirstDate containing #2/1/2018# instead.

    Then you can use DateAdd() to add 1 month to FirstDate, and again to subtract one day from that giving LastDate.

    Then just loop from FirstDate to LastDate:

    Code:
        Dim FirstDate As Date
        Dim LastDate As Date
        Dim EachDate As Date
    
        FirstDate = #2/1/2018#
        LastDate = DateAdd("d", -1, DateAdd("m", 1, FirstDate))
        For EachDate = FirstDate To LastDate
            Debug.Print EachDate
            'Or insert EachDate rows into MONTH table.
        Next
    This assumes your weird "02-2018" was February 2018.
    Tks bro!
    Work fine!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width