Geeks With Blogs

News

View Anthony Trudeau's profile on LinkedIn

Add to Technorati Favorites


Anthony Trudeau

I've been racking my brain with an error for quite awhile now regarding adding a parameter to a collection for an ADO Command object.  The scenario is that I have a SQL query called from Access against a SQL Server database that has one character parameter.

The relevant piece of code is:

Dim param As ADODB.Parameter
Set param = cmd.CreateParameter("@p1", adVarChar, adParamInput, 20, val)
cmd.Parameters.Append param

The ADO documentation for the CreateParameter method states:

This method does not automatically append the Parameter object to the Parameters collection of a Command object. This lets you set additional properties whose values ADO will validate when you append the Parameter object to the collection.

When I ran my test function it failed with Object Required and an error number of 424.  I finally noticed that after I called CreateParameter that there was indeed a parameter in the collection.  So it turns out that the ADO documentation in this case is wrong.

I was able to resolve the problem by directly instantiating the Parameter and then appending it to the collection -- that is I did not use the CreateParameter method.

 

Posted on Saturday, October 28, 2006 5:47 PM bugs | Back to top


Comments on this post: Object Required (424) with Parameter collection

# re: Object Required (424) with Parameter collection
Requesting Gravatar...
can you please send me a code that do your resolve way. i got the same problem/error.
THANKS. moshe_ga@malam.com
Left by Moshe Gal on Jul 05, 2009 2:23 AM

# re: Object Required (424) with Parameter collection
Requesting Gravatar...
i have the same problem with following code . can any one help me?
Sub PopulateStudName()
Dim recStud As New ADODB.Recordset
wcboStudName.clear
If recStud.State = adStateOpen Then recStud.Close
If wcboClass.Text = "" Then

recStud.Open "Select distinct studentmaster.studfirstname,studentmaster.studmiddlename,studentmaster.studlastname,feescollectiondetails.AcadYear,feescollectiondetails.ClassLevel,studentacaddetails.studclass From studentmaster sm,studentacaddetails sa,feescollectiondetails fc where sm.studid=sa.studid and sa.studid=fc.studid and fc.AcadYear='" & IIf(WcboStudAcadYr.Text = "", fc.AcadYear, WcboStudAcadYr.Text) & "' and fc.ClassLevel='" & IIf(wcboCLevel.Text = "", "CL01", getID(wcboCLevel.Text)) & "' Order by sm.studfirstname", cn, 1, 3, adCmdText
Else
recStud.Open "Select distinct studentmaster.studfirstname,studentmaster.studmiddlename,studentmaster.studlastname,feescollectiondetails.AcadYear,feescollectiondetails.ClassLevel,studentacaddetails.studclass From studentmaster sm,studentacaddetails sa,feescollectiondetails fc where sm.studid=sa.studid and sa.studid=fc.studid and fc.AcadYear='" & IIf(WcboStudAcadYr.Text = "", fc.AcadYear, WcboStudAcadYr.Text) & "' and fc.ClassLevel='" & IIf(wcboCLevel.Text = "", "CL01", getID(wcboCLevel.Text)) & "' and sa.studclass='" & wcboClass.Text & "' Order by sm.studfirstname", cn, adOpenKeyset, adLockOptimistic, adCmdText

'recStud.Open "Select distinct Name,AcadYear,ClassLevel,ClassID From qFees where AcadYear='" & IIf(WcboStudAcadYr.Text = "", AcadYear, WcboStudAcadYr.Text) & "' and ClassLevel='" & IIf(wcboCLevel.Text = "", "CL01", getID(wcboCLevel.Text)) & "' and ClassID='" & wcboclass.Text & "' Order by Name", cn, adOpenKeyset, adLockOptimistic, adCmdText
End If

Do While Not recStud.EOF
If IsNull(recStud.Fields(0).Value) = False Then wcboStudName.AddItem recStud.Fields(0).Value & ""
recStud.MoveNext
Loop
Set recStud = Nothing
end sub
Left by kp on Jul 28, 2009 2:22 AM

Your comment:
 (will show your gravatar)


Copyright © Anthony Trudeau | Powered by: GeeksWithBlogs.net