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 Chris Miller 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.
 
It's hard to tell without looking at your form but I think the syntax in your parameter query is incorrect. Is your parameter of the query actually called "Forms!SpreadSheet!cboClientSelect"? Another I would do is just rewrite the query dynamically, something like:

Dim sSQL as string
sSQL="Select Count(x) FROM tableWhatever WHERE WhatEverField=" & Chr(34) & cboClientSelect.value & chr(34)
set rstquery=currentdb.openrecordset(sSQL,dbopenforwardonly)
if stuff
txtboxWhatever=rstquery.fields(0).value
endif

This is a little quick and dirty but it should be enough to get you going?

I hope this helps,
Rewdee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top