sachin.modak
New member
- Local time
- Today, 21:03
- Joined
- Oct 29, 2007
- Messages
- 3
Hi,
I'm having 2 functions in my application in two different modules .
They are as follows.
Public Function GetNextNumber() As Variant
Dim strSQL As String
Dim rs As Recordset
GetNextNumber= Null
// creating sql to execute MYSP stored procedures with 2 parameteres
strSQL = "EXEC MySP '" & param 1 & "','" & param 2 & "'"
Set rs = ExecProc(strSQL)
If (rs Is Nothing) Or (rs.EOF And rs.BOF) Then
Call ShowErrors
Else
GetNextNumber= rs!Value
End If
ExitPoint:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Function
ErrHandler:
MsgBox err.Number & " - " & err.Description
Resume ExitPoint
End Function
Function ExecProc(strCommandText As String) As Recordset
Dim db As Database
Dim qdef As QueryDef
Dim rst As Recordset
On Error GoTo ErrHandler
Set db = CurrentDb()
Set qdef = db.CreateQueryDef("")
qdef.Connect = CONNECTSTRING
qdef.ODBCTimeout = 600
qdef.ReturnsRecords = True
qdef.Sql = strCommandText
Set rst = qdef.OpenRecordset()
Debug.Print rst.Fields(0).Value
Set ExecProc = rst
rst.Close
Set rst = Nothing
Set qdef = Nothing
ExitPoint:
On Error Resume Next
qdef.Close
Set qdef = Nothing
Exit Function
ErrHandler:
Set ExecProc = Nothing
Resume ExitPoint
End Function
When I'm trying to execute stored procedure thru MS Access.I'm getting error at line indicated by red color.
the error is (Error 91:Object variable or With block variable not set.)
So can anyone help me out ?
Thanks in advance.
Regards,
Sachin
I'm having 2 functions in my application in two different modules .
They are as follows.
Public Function GetNextNumber() As Variant
Dim strSQL As String
Dim rs As Recordset
GetNextNumber= Null
// creating sql to execute MYSP stored procedures with 2 parameteres
strSQL = "EXEC MySP '" & param 1 & "','" & param 2 & "'"
Set rs = ExecProc(strSQL)
If (rs Is Nothing) Or (rs.EOF And rs.BOF) Then
Call ShowErrors
Else
GetNextNumber= rs!Value
End If
ExitPoint:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Function
ErrHandler:
MsgBox err.Number & " - " & err.Description
Resume ExitPoint
End Function
Function ExecProc(strCommandText As String) As Recordset
Dim db As Database
Dim qdef As QueryDef
Dim rst As Recordset
On Error GoTo ErrHandler
Set db = CurrentDb()
Set qdef = db.CreateQueryDef("")
qdef.Connect = CONNECTSTRING
qdef.ODBCTimeout = 600
qdef.ReturnsRecords = True
qdef.Sql = strCommandText
Set rst = qdef.OpenRecordset()
Debug.Print rst.Fields(0).Value
Set ExecProc = rst
rst.Close
Set rst = Nothing
Set qdef = Nothing
ExitPoint:
On Error Resume Next
qdef.Close
Set qdef = Nothing
Exit Function
ErrHandler:
Set ExecProc = Nothing
Resume ExitPoint
End Function
When I'm trying to execute stored procedure thru MS Access.I'm getting error at line indicated by red color.
the error is (Error 91:Object variable or With block variable not set.)
So can anyone help me out ?
Thanks in advance.
Regards,
Sachin