Function Call problem

Stoss

Registered User.
Local time
Today, 01:40
Joined
Nov 5, 2010
Messages
107
Hello all,

I am having a bit of a brain freeze and I need help with this function call.

The following code is currently placed in a form. I also need to use the the same code for a report so I wanted to move the code to Module1 where I can call it from either the form or report.

The trouble I am having is what parameters I need to set up in the function.

Code:
On Error GoTo ErrHandler

    If strPriority = "Priority 1 (Immediately)" Then
        Me.txtClosedBy = "This discrepancy must be fixed IMMEDIATELY!"

        'Sets Priority 2 Priorities
        ElseIf strPriority = "Priority 2 (7-Days)" Then
            If ([OPEN_DATE] + 7) >= Date Then
                If ([OPEN_DATE] + 7) <> Date Then
                    Me.txtClosedBy = "This discrepancy is " & DateDiff("d", [OPEN_DATE], Date) & " day(s) old and must be closed by " & DateAdd("d", DateDiff("d", Date - 7, [OPEN_DATE]), Date) & ".  (" & DateDiff("d", Date - 7, [OPEN_DATE]) & " day(s) remaining)"
                Else
                    Me.txtClosedBy = "This discrepancy is due today!"
                End If
            Else
                Me.txtClosedBy = "This discrepancy is past due by " & DateDiff("d", [OPEN_DATE] + 7, Date) & " day(s)."
            End If
        
        'Sets Priority 3 Priorities
        ElseIf strPriority = "Priority 3 (30-Days)" Then
            If ([OPEN_DATE] + 30) >= Date Then
                If ([OPEN_DATE] + 30) <> Date Then
                    Me.txtClosedBy = "This discrepancy is " & DateDiff("d", [OPEN_DATE], Date) & " day(s) old and must be closed by " & DateAdd("d", DateDiff("d", Date - 30, [OPEN_DATE]), Date) & ".  (" & DateDiff("d", Date - 30, [OPEN_DATE]) & " day(s) remaining)"
                Else
                    Me.txtClosedBy = "This discrepancy is due today!"
                End If
            Else
                Me.txtClosedBy = "This discrepancy is past due by " & DateDiff("d", [OPEN_DATE] + 30, Date) & " day(s)."
            End If

        'Sets Priority 4 Priorities
        ElseIf strPriority = "Priority 4 (90-Days)" Then
            If ([OPEN_DATE] + 90) >= Date Then
                If ([OPEN_DATE] + 90) <> Date Then
                    Me.txtClosedBy = "This discrepancy is " & DateDiff("d", [OPEN_DATE], Date) & " day(s) old and must be closed by " & DateAdd("d", DateDiff("d", Date - 90, [OPEN_DATE]), Date) & ".  (" & DateDiff("d", Date - 90, [OPEN_DATE]) & " day(s) remaining)"
                Else
                    Me.txtClosedBy = "This discrepancy is due today!"
                End If
            Else
                Me.txtClosedBy = "This discrepancy is past due by " & DateDiff("d", [OPEN_DATE] + 90, Date) & " day(s)."
            End If

        'Sets Priority 5 Priorities
        ElseIf strPriority = "Priority 5 (As Required)" Then
            Me.txtClosedBy = "This discrepancy needs to be completed at first convenient time."
        Else
            Me.txtClosedBy = "Priority needs to be change to reflect current standards."
    End If

I am just unsure how to set this up properly so both the form or the report can utilize the same code.

Thanks,
Stoss
 
I managed to get it to work. Not sure how or why it works but I guess it is good to go.

-Stoss
 
If your Function is in a Module, then when you 'Call' it, you will need to pass to the Function the values in ControltxtClosedBy. Does [OPEN_DATE] need to be passed as well??

Set up your Function like this

Public Function myError(strClosedBy as String, datopenDate as Date) as String

<Your code here>

myError = "some text related to the Priority "

End Function


Call this Function either like this: Call myError(strClosedBy, Open_Date) OR

if myError(strClosedBy, Open_Date) = "some text related to the Priority"
then
etc....
end if
 

Users who are viewing this thread

Back
Top Bottom