Problem with calling a function

craigachan

Registered User.
Local time
Today, 01:44
Joined
Nov 9, 2007
Messages
285
I have the following function below.

When I use:
Call ChartAudit(me.PtID, me.PtName, "", "", "","", strNextVisit)
The function doesn't even run. It's just skipped over.

When I use:
Call ChartAudit(me.PID, me.PName, me.Proc, "", "","", strNextVisit)
the function does run.

The only difference that I can tell is 'Me.Proc'. I'm baffled why my first call doesn't make it run. Can anyone help me understand what I'm doing?

Code:
Public Function ChartAudit(PtID As String, _
                        PtName As String, _
                        Optional Proc As String, _
                        Optional ProcDate As Date, _
                        Optional XRecd As String, _
                        Optional XRetd As String, _
                        Optional strNextVisit As String)
On Error Resume Next
 
Dim qyPtChartAudit As String
Dim RC As Integer
Dim Record As Integer
RC = DCount("*", "QryChartauditptview")
' For Testing: MsgBox "PtID: " & PtID & Len(PtID) & ", PtName: " & PtName & Len(PtName) & ", Proc: " & Proc & Len(Proc) & ", ProcDate: " & _
        ProcDate & Len(ProcDate) & ", XRecd: " & XRecd & Len(XRecd) & ", XRetd: " & XRetd & Len(XRetd)
 
If RC = 0 Then
    DoCmd.OpenForm "ChartAuditView", acNormal, , , acFormAdd ', acHidden
    Dim frmCAV
    Set frmCAV = Forms!ChartAuditview
    frmCAV.aPID = PtID
    frmCAV.aPName = PtName
    If Len(Proc) > 0 Then
        frmCAV.aProc = Proc
    Else
        frmCAV.aProc = ""
    End If
    If Len(ProcDate) > 0 Then
        frmCAV.aDOS = ProcDate
    End If
 
    If Len(XRecd) > 0 Then
        frmCAV.aXrayRecd = XRecd
    Else
        frmCAV.aXrayRecd = ""
    End If
 
    'Tag ChartNote with nAuditID
    Forms!ChartGenConSx!nAuditID = frmCAV.AID
 
    DoCmd.Close acForm, "ChartAuditView"
Else
    DoCmd.OpenForm "ChartAuditPtView" ', , , , , acHidden
    Dim frmCAVPV
    Set frmCAVPV = Forms!ChartAuditPtView
    'For Testing: MsgBox "Len(frmCAVPV.Proc): " & Len(frmCAVPV.Proc)
    'For Testing:  MsgBox "Len(Xrecd): " & Len(XRecd) & "       Len(XRetd):  " & Len(XRetd) & "- " & XRetd & "-"
 
    'If frmCAVPV.XrayRecd = "" Then
    '     MsgBox "Len(frmCAVPV.XrayRecd): Space"
    'End If
    'If IsNull(frmCAVPV.XrayRecd) Then
    '    MsgBox "frmcavpv.xrayrecd - Null"
    'End If
 
    'If frmCAVPV.XrayRetd = "" Then
    '     MsgBox "Len(frmCAVPV.XrayRetd): Space"
    'End If
    'If IsNull(frmCAVPV.XrayRetd) Then
    '    MsgBox "frmcavpv.xrayretd - Null"
    'End If
 
    '-----XRayRecd
    If XRecd <> "" Then
        If frmCAVPV.XrayRecd = "" Or IsNull(frmCAVPV.XrayRecd) Then
            frmCAVPV.XrayRecd = XRecd
        Else
            frmCAVPV.XrayRecd = frmCAVPV.XrayRecd & vbCrLf & XRecd
        End If
    End If
 
    '-------ProcDate
    If ProcDate <> "" Then
        frmCAVPV.DOS = ProcDate
    End If
 
    '--------Proc
    'MsgBox Proc
    If Proc <> "" Then
        If Len(frmCAVPV.Proc) < 1 Or IsNull(frmCAVPV.Proc) Then
            frmCAVPV.Proc = Proc
        Else
            frmCAVPV.Proc = frmCAVPV.Proc & vbCrLf & Proc
        End If
    End If
 
    '----XRayRetd
    If XRetd <> "" Then
        If frmCAVPV.XrayRetd = "" Or IsNull(frmCAVPV.XrayRetd) Then
            frmCAVPV.XrayRetd = XRetd
        Else
            frmCAVPV.XrayRetd = frmCAVPV.XrayRetd & vbCrLf & XRetd
        End If
    End If
 
    '-----NextVisit
    If strNextVisit <> "" Then
        frmCAVPV.NextVisit = strNextVisit
    End If
 
    '------NextVisit on PtInfo
 
    If strNextVisit <> "" Then
        If IsNull(DLookup("PID", "CHANNotesTblPtInfo", "PID = Forms!ChartMain!nPID")) Then
            DoCmd.OpenForm "ChartTblPtInfo", , , , acFormAdd
            Forms!ChartTblPtInfo!PID = Trim(Forms!ChartMain!nPID)
            Forms!ChartTblPtInfo!PName = Forms!ChartMain!PName
            Forms!ChartTblPtInfo!NextVisit = strNextVisit
            DoCmd.Close acForm, "ChartTblPtInfo"
        Else
            DoCmd.OpenForm "ChartTblPtInfo", , , "PID = Forms!ChartMain!nPID", , acHidden
            Forms!ChartTblPtInfo!NextVisit = strNextVisit
            DoCmd.Close acForm, "ChartTblPtInfo"
        End If
     End If
 
    'Return any open form info
        If IsLoaded("ChartGenConSx") Then
           Forms!ChartGenConSx!nAuditID = frmCAVPV.AID
        End If
    DoCmd.Close acForm, "ChartAuditPtView"
 
End If
End Function
 
For optional parameters you do not use "" you just leave them blank and separated with the comma.
 
Thanks for your suggestion. I tried getting rid of all of the options so see if it would run different. That is why I had the "", but it didn't seem to work.

I also have a side question. If you leave an option blank, is the blank null or ""?

Any other suggestions on what might be wrong with my 'call'?
 
Well, I don't know if it would affect anything but I wouldn't name the input parameters the same as the fields on your form.
 
Thank SOS, I changed all of my params to make sure they were different. But unfortunately it did not help it run. Any other suggestions?
 
Not sure but remove the On Error Resume Next as that obscures errors that might give us a clue. I would avoid using that type of Error Handling if at all possible. It makes it so that you never know what hit you.
 
Last edited:
Thank you so much. One cannot underestimate the value of error handling. I found the problem, it was a "Type Mismatch". It's alway nice to have a second set of eyes when you need help.

Problem is fixed.
 
Glad to hear you got it working.
 

Users who are viewing this thread

Back
Top Bottom