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!

Item not found in this collection (but I know it's there!)

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
Dim prmClient As Parameter

' 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 = 0
Else
frm.txtDaysPaid = rstQuery.RecordCount
End If
' Give the number of records returned in a message box for the user.
' MsgBox "Query returned " & rstQuery.RecordCount & " records."
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.

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 htink, anyway). Any ideas or advice about what is wrong is appreciated. Almost identical code works great on a different form.
 
I see two things:

1) The variable frm has not been properly initialized. Do this:
[tab]Set frm = New Form_SpreadSheet
Same applies for the other two objects beneath it.

2) You need to provide the correct property on the combobox. Try the ListIndex property, but be aware that it can return -1 if no item is selected.

Chip H.

 
i agree with chip, you might have a problem with your frm variable. Check the Form_Spreadsheet and see if it has all the controls/public functions or variables that you are referring to from the frm variable.

arcanist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top