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!

Parameter Query that gets its value from a combo box- error

Status
Not open for further replies.

LowBrow

Technical User
Jun 1, 2001
100
US
Here is the code:
Sub cboClientSelect_AfterUpdate()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim frm As Form_SpreadSheet
Dim qdf As DAO.QueryDef

' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[ClientID] = " & Me![cboClientSelect]
Me.Bookmark = Me.RecordsetClone.Bookmark

' Update txtDaysPaid based on record count

Set frm = Form_SpreadSheet
Set dbs = CurrentDb
Set dbsQuery = CurrentDb

' Open QueryDef object (a compiled query in the database named FindActualDays.
Set qdf = dbsQuery.QueryDefs("FindActualDays")
' Refresh QueryDefs collection.
dbs.QueryDefs.Refresh
' Set parameter for the query based on Client entered
' in SpreadSheet form.

qdf.Parameters("Forms!SpreadSheet!cboClientSelect") _
= frm.cboClientSelect

' Open Recordset object (the query). Then count all the records returned.
Set rstQuery = qdf.OpenRecordset()
' Fill or leave Null the field DaysPaid based on the number of records returned.
If rstQuery.RecordCount = 0 Then
frm.txtDaysPaid = Null
Else
frm.txtDaysPaid = rstQuery.RecordCount
End If

rstQuery.Close
Set dbs = Nothing


End Sub

What it is supposed to do is:
fill records on the subform (spreadsub) based on the client selected and fill the text box txtDaysPaid with number of records returned in the query FindActualDays for the client selected.

The error highlights the line:
qdf.Parameters("Forms!SpreadSheet!cboClientSelect") _
= frm.cboClientSelect
telling me that I have not properly identified frm.cboClientSelect, but I have (I think, anyway). Any ideas or advice about what is wrong is appreciated.
 
Thanks JoaoTL, I tried it but it didn't work. I got the same error (Item not found in this collection). The control, cboClientSelect, exists on the main form, not the subform.
Thanks for trying, though! All help is much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top