none
Compilation error RRS feed

  • Question

  • I created two date fields - Training STart date and Training End dAte.

    On the After update event of the end date field,  I have the following - Call IsValidDate

    the CAll ISValidate procedure is has follows:

    But when I debug.. I get the following error - Compile error... Argument not optional.


    olu Solaru

    Thursday, June 6, 2019 3:35 PM

Answers

  • That makes sense. 

    IsValidDate is expecting 4 input variables: txtTrainingStartDate, txtTrainingEndDate, txtTravelStartDate  & txtTravelEndDate.  So when you call it, you need to supply them.  Something like:

    Call IsValidDate(Me.ControlName1, Me.ControlName2, Me.ControlName3, Me.ControlName4)


    Daniel Pineault, 2010-2018 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    • Proposed as answer by Gustav BrockMVP Tuesday, June 11, 2019 6:46 AM
    • Marked as answer by osolaru71 Tuesday, June 11, 2019 7:44 PM
    Monday, June 10, 2019 11:00 PM

All replies

  • Can you post your code instead of an image.  The image is very small and makes it hard to read.

    When you debug, which line is highlighted as problematic?

    When I compile it, I get no errors?
    You do have an issue with your function though, for the return False, your variable is improperly named.

    For anyone else, below is the OCRed code block

    Private Function IsValidDate(txtTrainingStartDate As Date, txtTrainingEndDate As Date, txtTravelStartDate As Date, txtTravelEndDate As Date)
        Dim strMsg                As String

        If IsDate(txtTrainingStartDate) = True And IsDate(txtTrainingEndDate) = True Then
            If txtTrainingStartDate > txtTrainingEndDate Then
                strMsg = "Training Start date must be EQUAL to or LESS THAN Training End Date."
            End If
        Else
            strMsg = "Both the Training Start Date and the Training End Date are required"
        End If

        If txtTrainingStartDate > txtTravelStartDate Then
            strMsg = "Travel Start Date must be EQUAl to or LESS THAN the Training Start Date"
        End If
        If Len(strMsg) = 0 Then
            IsValidDate = True
        Else
            MsgBox strMsg, vbOKOnly, "Date Entry Error"    'Windows Message Box
            IsValdate = False
        End If
    End Function


    Daniel Pineault, 2010-2018 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net



    Thursday, June 6, 2019 5:43 PM
  • First, always insert Option Explicit at the top of your code modules. Set that as default under menu Tools, Options, Editor, Require Variable Declaration:

    Options

    Then you would have found the error at once:

    IsValdate = False

    Also, as you declare all arguments as Date, this line has no use, as - at this point - the values can't be anything else than date values:

    If IsDate(txtTrainingStartDate) = True And IsDate(txtTrainingEndDate) = True Then


    Gustav Brock

    Saturday, June 8, 2019 10:41 AM
  • Thanks for responding Gustav.. I fixed the lines as you suggested.  And I made sure I called the correct function - Call IsValidDate

    But I still get the same error...

    This is the function being called

    Private Function IsValidDate(txtTrainingStartDate As Date, txtTrainingEndDate As Date, txtTravelStartDate As Date, txtTravelEndDate As Date)
    Dim strMsg As String
        If txtTrainingStartDate > txtTrainingEndDate Then
            strMsg = "Training Start date must be EQUAL to or LESS THAN Training End Date."
        Else
           strMsg = "Both the Training Start Date and the Training End Date are required"
    End If

    If txtTrainingStartDate > txtTravelStartDate Then
       strMsg = "Travel Start Date must be EQUAl to or LESS THAN the Training Start Date"
    End If
    If Len(strMsg) = 0 Then
     IsValidDate = True
    Else
        MsgBox strMsg, vbOKOnly, "Date Entry Error" 'Windows Message Box
        IsValidDate = False
    End If
    End Function

    Private Sub txtTrainingEndDate_AfterUpdate()
        Call IsValidDate  - - This is the line it has a problem with.

    End Sub


    olu Solaru

    Monday, June 10, 2019 10:44 PM
  • That makes sense. 

    IsValidDate is expecting 4 input variables: txtTrainingStartDate, txtTrainingEndDate, txtTravelStartDate  & txtTravelEndDate.  So when you call it, you need to supply them.  Something like:

    Call IsValidDate(Me.ControlName1, Me.ControlName2, Me.ControlName3, Me.ControlName4)


    Daniel Pineault, 2010-2018 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    • Proposed as answer by Gustav BrockMVP Tuesday, June 11, 2019 6:46 AM
    • Marked as answer by osolaru71 Tuesday, June 11, 2019 7:44 PM
    Monday, June 10, 2019 11:00 PM
  • Thank You that worked.

    olu Solaru

    Tuesday, June 11, 2019 7:45 PM