Some of the replies so far have been misleading, and the actual answer appears to have been
completely missed.
try using
.parameters("@PROJECT_ID") = forms!...
instead...
This works, but it's no different than specifying the parameter at creation time. Not going to help.
No append is needed only if you do Parameters.Refresh. But this is poor practice as it necessitates a round trip to the server simply for convenience. If you want Parameters in your collection, you have to add them
somehow. Best practice is Append.
Item cannot be found in the collection corresponding to the requested name or ordinal.
As I said, you have to create the parameter before you can access its properties. Sorry about the confusion.
danvlas said:
Place another comma after adParameInput.
Now you have the parameter value in the 'size' position...
Ding ding ding ding ding. There's the answer. Let's fix your original code. First, see the
ADO CreateParameter Method.
It says
name, type, drection, size, value.
Size is missing, just like danvlas said, who deserves a star by the way, please click on "Thank danvlas for this valuable post!"
Code:
With cmd
.ActiveConnection = cnn
.CommandText = "dbo.SP_TravelRate"
.CommandType = adCmdStoredProc
[blue].Prepared = False 'unless you keep the command object lying around to reuse, save some effort by the server[/blue]
.Parameters.Append .CreateParameter("@EMPLOYEE_ID", adInteger, [COLOR=white red],[/color] adParamInput, Forms!frmwork_entry.SubFrmWork.Form!Employee_ID)
.Parameters.Append .CreateParameter("@PROJECT_ID", adInteger, adParamInput, [COLOR=white red],[/color] Forms!frmwork_entry.SubFrmWork.Form!Proj_ID)
.Execute
End With
you have to first load the results of the stored procedure into a recordset, then set the combobox's recordset property to the loaded recordset.
That works. But why not set the rowsource property instead? ADPs work that way and it's a far sight easier:
Code:
Me.Controls!cboTravelRate.RowSource = "EXEC dbo.SP_TravelRate " & Forms!frmwork_entry.SubFrmWork.Form!Employee_ID & ", " & Forms!frmwork_entry.SubFrmWork.Form!Proj_ID
You do have to pay attention to SQL injection. But these look like values not exposed to the user. In any case, you can use some scrubbing to make sure the values contain only numbers.
If it was a form it would be even easier. In the form properties at design time you would set the RecordSource property to "EXEC dbo.SP_TravelRate ?, ?" where the question marks are parameter placeholders, and the InputParameters property would be "[Forms]![frmwork_entry].[SubFrmWork].[Form]![Employee_ID], [Forms]![frmwork_entry].[SubFrmWork].[Form]![Proj_ID]".
If you really want to use a parameterized command object instead of text, create a generic function or procedure that does the work for you, code it right once and reuse it over and over again. You should NOT be declaring connections and commands and things over and over again throughout your code. What a mess.
[COLOR=black #d0d0d0]When I walk, I sometimes bump into things. I am closing my eyes so that the room will be empty.[/color]