PRB: Error 40041 When Calling RDO Parameters Through User ConnectionID: Q199128
|
Referencing parameters by name using the User Connection Designer (UCD) generates the following error:
The error occurs if the parameter's properties have been viewed in the Query Properties page prior to calling the parameter by name.Error 40041 "Object collection: Couldn't find item indicated by text".
When calling parameters by name using UCD or Remote Data Objects (RDO), each parameter's name should be preceded by an "@." When viewing the parameter's properties, the "@" prefix is removed from the parameter name. This causes RDO not to recognize the parameter anymore and error 40041 occurs.
Here are two ways to work around this behavior:
This behavior is by design.
CREATE PROCEDURE Test @ID1 int,
@ID2 int
AS
DECLARE @RetParam int
SELECT @RetParam = @ID1 + @ID2
RETURN @RetParam
Go
Option Explicit
Dim cn As New UserConnection1
Dim qry As New rdoQuery
Dim lngTemp As Long
Dim intReturn As Integer
Dim er As rdoError
Private Sub Command1_Click()
On Error GoTo UC_Error
' Establish connection.
cn.EstablishConnection rdDriverNoPrompt
Set qry = cn.rdoQueries("Query1")
qry("@ID1") = 2
qry("@ID2") = 3
qry.Execute
lngTemp = qry.rdoParameters("RETURN_VALUE")
' Check to see if you have a return value.
If lngTemp = vbNull Then
MsgBox "Sorry no value was returned back", , "Error occurred"
GoTo Free
Else
intReturn = lngTemp
End If
MsgBox "Sum of ID1 and ID2 = " & intReturn, , "Output"
Free:
Set qry = Nothing
Set cn = Nothing
Exit Sub
UC_Error:
For each er in rdoErrors
MsgBox er.Number & ": " & er.Description
Next er
End Sub
For more information on the connection designer, please refer to the following Microsoft Knowledge Base article:
Q166281 HOWTO: Create and Implement a UserConnection
Additional query words:
Keywords : kbDatabase kbRDO kbSQLServ kbUCDesigner kbVBp
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 13, 1999