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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need hlep loading a list box with a stored procedure

Status
Not open for further replies.

batteam

Programmer
Sep 12, 2003
374
US
I am trying to pass a parameter from an Access 2000 Project form over to a Stored Procedure so I can fill a list box from a table, based on the selection criteria of the passed parameter. But the parameter isn't being passed from the form for some reason. Every time the stored procedure starts to run, I get the 'pop up' message box asking for my parameter (in my example its: @varIONSNo). This same code works great when filling individual control boxes on forms, but I cannot get it to pass the parameter when trying to fill a list (or combo) box. Any help would be greatly appreciated.
My code behind my list box on enter is:

Dim cmdlstBox As ADODB.Command
Set cmdlstBox = New ADODB.Command

cmdlstBox.ActiveConnection = CurrentProject.Connection
cmdlstBox.CommandText = "FillListBox"
cmdlstBox.CommandType = adCmdStoredProc

cmdlstBox.Parameters("@varIONSNo").Value = txtIONSNo
cboEmployeeData.RowSource = "FillListBox"
Me.cboEmployeeData.Requery
End sub

And my stored procedure code is:

Alter Procedure FillListBox
@varIONSNo char(7)

As
Select employ_ID, first_name, last_name
From dbo_ZITASSOC_DATA
Where employ_ID = @varIONSNo
Order by employ_ID
/* set nocount on */
return

When I do supply the parameter manually into the pop up box, the list control fills like it should. But why am I not able to pass the parameter over to the stored procedure thru my code? I've tried many combinations of defining the parameter in Access but the results are always the same.
I've also directly bound the stored procedure to the list box in its property box but that didn't help either. Any help would be appreciated.
 
I found my solution. This exact problem was addressed in these Tech Tip pages last July. Seems that Access 2000 Projects has a bug in attempting to send a parameter to a stored procedure for a combo or list box. I did get the code on how to perfom this process from reponses to those earlier requests for help on this:

Dim strParameters As String
Dim strExec As String

Private Sub lstClientPolicyList_Enter()
strParameters = Forms!frmCounterOfferMainEntry![txtSubjectID] '''field on my form
strExec = "Exec COF_FillListBox" & strParameters

lstClientPolicyList.Requery
End Sub

And my Stored Procedure code is:

Alter Procedure COF_FillListBox
@txtSubjectID int
As

Select subject_id, polnum as [Policy No.],
Case referral_cd when 'F' then 'Field' else 'CVC1' end as [Refer to],
embedded_Value as [EV], ev_decile as [Conserve]
From COF_Segmentation
Where (subject_id) = @txtSubjectID
Order by [EV]
Return

Also, I'm doing a clear to "" and a requery on the list box when the focus is lost in the txtSubjectID text.

To those of you who helped solve this problem a few months ago: Thank you very much!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top