Recordset based on a Parameterised Query

G

Guest

I am trying to open a recordset that is based on a parameterised query. Here
is the code:

Private Sub cmdRecCnt_Click()
Dim rec As DAO.Recordset

Set rec = CurrentDb().OpenRecordset("qryGetInfo")
rec.MoveLast
txtRecCnt.Value = rec.RecordCount
rec.Close

End Sub

There are 4 text boxes on a form that supply the filter criteria for 4
fields in the query "qryGetInfo".

When I click the button to run the subroutine, I get an error that says:
"Run-time error 3061
Too few parameters. Expected 4"

All 4 text boxes are populated with valid data. I also have a list box on
the same form that displays the results of the same query with no problem. I
would like "txtRecCnt" to display the number of records displayed in the list
box.

Thanks in advance for the help.
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can use the ListBox's property ListCount to get the count, with a
caveat. Set the ControlSource of the TextBox to something like this:

=lstListBoxName.ListCount

In versions before Access 2000, that would return -1 if there weren't
any items in the ListBox. So I did this:

=lstListBoxName.ListCount + IsNull(lstListBoxName.Column(0,0))

Which would return 0 when the ListBox was empty.

Be sure to change the "lstListBoxName" to your ListBox's name.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRDWKsIechKqOuFEgEQK/uQCfTlRuhVWiH1lNdbzxZoDH6vQbmAEAoIzv
kPTxKKsdeCs0j+uluKBju+zP
=fGRG
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top