• DateAdd interval (a2k3)

    Author
    Topic
    #411560

    I’ve inherited this function allows you to enter a start date and end date with an interval and it proceeds to generate records of billing periods between the start and end dates with the billing period duration you selected in interval and inserts it into a table.

    The way it is currently the start date is the first of the month and the last day of the billing period is the first day of the following month, if the interval is month. This means that the first day of the month can be in two billing periods. The end date of the billing period should be plus 1 month minus 1 day. How do I amend this code to make that correction? Is it as simple as putting -1 behind the DateAdd arguments?

    E

    Function funGenerateBill(dtmStartDate As Date, dtmEndDate As Date, _
    txtDuration As String) As Boolean
    Dim strInterval As String
    Dim nIncrement As Integer
    Dim dtmBillStartDate As Date

    Select Case txtDuration
    Case “Monthly”
    strInterval = “m” ‘ for months
    nIncrement = 1 ‘ monthly so this will be 1
    Case “Quarterly”
    strInterval = “m” ‘ Increment in months
    nIncrement = 3 ‘ 3 months for single quarter
    End Select
    dtmCurrentDate = dtmStartDate
    Do
    dtmBillStartDate = dtmCurrentDate
    dtmCurrentDate = DateAdd(strInterval, nIncrement, dtmCurrentDate)
    CurrentDb.Execute “Insert into tblPymt (dtmBillStartDate,dtmBillEndDate) values (“,#” & Format(dtmBillStartDate, “mm/dd/yyyy”) _
    & “# , #” & Format(dtmCurrentDate, “mm/dd/yyyy”));”
    Loop

    End Function

    Viewing 1 reply thread
    Author
    Replies
    • #893040

      Try replacing

      CurrentDb.Execute “Insert into tblPymt (dtmBillStartDate,dtmBillEndDate) values (“,#” & Format(dtmBillStartDate, “mm/dd/yyyy”) _
      & “# , #” & Format(dtmCurrentDate, “mm/dd/yyyy”));”

      with

      CurrentDb.Execute “Insert into tblPymt (dtmBillStartDate,dtmBillEndDate) values (“,#” & Format(dtmBillStartDate, “mm/dd/yyyy”) _
      & “# , #” & Format(dtmCurrentDate – 1, “mm/dd/yyyy”));”

      I assume the code you posted is a simplified version, since as it is, the loop would never end.

      • #893042

        You’ve done it again! Thanks.

        It was indeed stripped down code.

        E

      • #893043

        You’ve done it again! Thanks.

        It was indeed stripped down code.

        E

    • #893041

      Try replacing

      CurrentDb.Execute “Insert into tblPymt (dtmBillStartDate,dtmBillEndDate) values (“,#” & Format(dtmBillStartDate, “mm/dd/yyyy”) _
      & “# , #” & Format(dtmCurrentDate, “mm/dd/yyyy”));”

      with

      CurrentDb.Execute “Insert into tblPymt (dtmBillStartDate,dtmBillEndDate) values (“,#” & Format(dtmBillStartDate, “mm/dd/yyyy”) _
      & “# , #” & Format(dtmCurrentDate – 1, “mm/dd/yyyy”));”

      I assume the code you posted is a simplified version, since as it is, the loop would never end.

    Viewing 1 reply thread
    Reply To: DateAdd interval (a2k3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: