0

This is my code, and thoughs on this error:
Conversion from string "MM/yyyy" to type 'Date' is not validerror:

    Public Function AddNextMonthDue(ByRef OldNMD As String, ByRef MonthsToAdd As String) As String
        Dim dOldNMD As Date
        Dim dNewNMD As Date
        Dim sOldNMD As String
        If Len(OldNMD) = 4 Then ' MMDD format
            sOldNMD = "20" & Right(OldNMD, 2) & Left(OldNMD, 2) & "01"
        Else
            sOldNMD = OldNMD ' YYYYMMDD format
        End If
        dOldNMD = CDate(Mid(sOldNMD, 5, 2) & "/1/" & Left(sOldNMD, 4))         

        dNewNMD = DateAdd(Microsoft.VisualBasic.DateInterval.Month, CShort(MonthsToAdd), dOldNMD)
        AddNextMonthDue = Format(CDate(dNewNMD), "MMyy")

    End Function
2
Contributors
1
Reply
13
Views
4 Years
Discussion Span
Last Post by Reverend Jim
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.