Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch error on EXIT FUNCTION??

Status
Not open for further replies.

usp004

ISP
Jul 10, 2000
46
0
0
US
I am getting a Runtime Error (Type Mismatch Err.Number=13) on the EXIT FUNCTION line in the following class module... can someone help me??

Public Function get_header_info(strSessionId As String) As ADODB.Recordset
On Error GoTo err:

Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Dim cmd As ADODB.CommandSet rs = New ADODB.Recordset
Set cn = New ADODB.Connection
Set cmd = New ADODB.Command

cn.Open gConnectString
rs.CursorLocation = adUseClient
rs.Open "fa_get_header_info '" & strSessionId & "'", cn, adOpenKeyset, adLockOptimistic, adCmdText

Set rs.ActiveConnection = Nothing
Set get_header_info = rs

If rs.EOF And rs.BOF Then
mlngNumOfPOs = 0
Else
mlngNumOfPOs = rs.RecordCount
End If

If cn.State <> 0 Then
cn.Close
Set cn = Nothing
End If

Exit Function

err:
Set cn = Nothing
Set rs = Nothing

End Function
 
It seems there is a problem involving how you're assigning the variable the return value of get_header_info and/or the data type of the variable. Check the data type of that variable and make sure that you're using syntax like:

Dim result As ADODB.Recordset
Set result=get_header_info(&quot;whatever your connect string is&quot;)
 
If strSessionID is numeric or variant, try the cstr function to convert to a string as in
rs.Open &quot;fa_get_header_info '&quot; & cstr(strSessionId) & &quot;'&quot;, cn, adOpenKeyset, adLockOptimistic, adCmdText
 
Why are you setting a module level variable in the function? If you need the number of records get that in the code that called the function. Also, you do not clean-up RS unless there is an error condition.

Try this:


Public Function get_header_info(strSessionId As String) As ADODB.Recordset
On Error GoTo err:

Dim rs As ADODB.Recordset

set rs = createobject(&quot;adodb.Recordset&quot;)
RS.LockType = adLockBatchOptimistic
RS.CursorLocation = adUseClient
rs.Open &quot;fa_get_header_info '&quot; & strSessionId & &quot;'&quot;, gConnectionString, adOpenKeyset, adLockOptimistic, adCmdText

Set rs.ActiveConnection = Nothing
Set get_header_info = rs

Set rs = Nothing

Exit Function

err:
Set rs = Nothing

end function

Calling program:
dim objrs as adodb.recordset
set objrs = get_header_info(strsessionid)
mlngNumOfPOs = objrs.recordcount
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top