Call a public function, Compile error: Argument not optional

Chief

Registered User.
Local time
Today, 03:23
Joined
Feb 22, 2012
Messages
156
Hello,
I wish to call on a Public Function from my Module_General
This is the Function I wish to use:

Code:
' Check all dates on form to ensure they are not less than the delivery date (TxtCustomerPreferredDate).
Public Function DateCheck(form_name As String)
Dim txtmessage As String
txtmessage = ""

    If Forms(form_name).ChkCarcassCut = True Then
        If Forms(form_name).ChkCC_Cut = False And Forms(form_name).TxtCarcassCut_Due > Forms(form_name).TxtCustomerPreferredDate Then
            txtmessage = "Warning! Delivery/Completion Date cannot be before a process." & vbCrLf & txtmessage
            Forms(form_name).TxtCarcassCut_Due.BackColor = vbRed
            Forms(form_name).TxtCarcassCut_Due.ForeColor = vbWhite
            Forms(form_name).TxtCustomerPreferredDate.BackColor = vbRed
            Forms(form_name).TxtCustomerPreferredDate.ForeColor = vbWhite
            Forms(form_name).TxtCarcassCut_Due.SetFocus
        Else
            Forms(form_name).TxtCarcassCut_Due.BackColor = vbWhite
            Forms(form_name).TxtCarcassCut_Due.ForeColor = vbBlack
            Forms(form_name).TxtCustomerPreferredDate.BackColor = vbWhite
            Forms(form_name).TxtCustomerPreferredDate.ForeColor = vbBlack
        End If
        
        
        
    End If
End Function

This is where I am getting the Compile error: I do not know where to put the Call:

Code:
' Check all fields are complete, check process dates are not later than delivery
Private Sub BtnClose_Click()
    If IsNull(CboDeliverPickUp) Then
        MsgBox "Please select Delivery or Pick up", , "Missing Details"
        CboDeliverPickUp.BackColor = vbRed
        CboDeliverPickUp.ForeColor = vbWhite
        CboDeliverPickUp.SetFocus
    ElseIf IsNull(CboSupplyInstall) Then
        MsgBox "Please select Supply or Install", , "Missing Details"
        CboSupplyInstall.BackColor = vbRed
        CboSupplyInstall.ForeColor = vbWhite
        CboSupplyInstall.SetFocus
    ElseIf ChkTwoPakPaint = True And IsNull(CboPaintID) Then
        MsgBox "Please select paint finish", , "Missing Details"
        CboPaintID.BackColor = vbRed
        CboPaintID.ForeColor = vbWhite
        CboPaintID.SetFocus
    ElseIf ChkSkill = True And IsNull(CboSkill) Then
        MsgBox "Please select Skilled Labour required", , "Missing Details"
        CboSkill.BackColor = vbRed
        CboSkill.ForeColor = vbWhite
        CboSkill.SetFocus
    ElseIf IsNull(TxtCustomerPreferredDate) Then
        TxtCustomerPreferredDate.BackColor = vbRed
        TxtCustomerPreferredDate.ForeColor = vbWhite
        TxtCustomerPreferredDate.SetFocus
    Else
        CboDeliverPickUp.BackColor = vbWhite
        CboDeliverPickUp.ForeColor = vbBlack
        CboSupplyInstall.BackColor = vbWhite
        CboSupplyInstall.ForeColor = vbBlack
        CboPaintID.BackColor = vbWhite
        CboPaintID.ForeColor = vbBlack
        CboSkill.BackColor = vbWhite
        CboSkill.ForeColor = vbBlack
        TxtCustomerPreferredDate.BackColor = vbWhite
        TxtCustomerPreferredDate.ForeColor = vbBlack
    Call DateCheck
        DoCmd.Close
    End If
End Sub

Thank you.
 
you add your form's name to DateCheck function, see the function.
also the error message is suggestive.

Call DateCheck("yourFormName")
 
OK, let's split this question. I don't know where to put the call either. But the "Argument not optional" is because when you declared the DateCheck code you (a) specified a function and (b) specified that it needed a form name as an argument. When you actually USED it, you (a) used it as a Sub and (b) did NOT provide a form name.
 
OK, let's split this question. I don't know where to put the call either. But the "Argument not optional" is because when you declared the DateCheck code you (a) specified a function and (b) specified that it needed a form name as an argument. When you actually USED it, you (a) used it as a Sub and (b) did NOT provide a form name.
Thank you,
Learning everyday.
 
Thank you for the suggestions and knowledge,
I think I am out of my depth with this one.

I have added the function to the form, and I'll need to repeat for all of my date checks.

Thanks again, appreciate it.
 

Users who are viewing this thread

Back
Top Bottom