vb code to Test results of a query is missing something

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some simple code that tests the result of a query before opening a
form with those results...

This has previously worked with no problems... however, what I'm doing
differently in this instance is that the query I'm testing is getting its
parameter from a combo box on a form (cmbGrpSearch). Is this why I'm getting
the following error:

"Run time Error 3061 Too Few Parameters. Expected 1"

when I run the following code:

'==============================================
Dim db As DAO.Database
Dim rsChk As DAO.Recordset

Set db = CurrentDb

Set rsChk = db.OpenRecordset("qryGroupSearchResults", dbOpenForwardOnly)

With rsChk
If Not .EOF And Not .BOF Then
DoCmd.OpenForm "frmGrpSearchResults"
Else
MsgBox "There are no subscribers currently using group #: " &
Me.cmbGrpSearch, vbInformation, "No Data Found!"
End If
End With


Set rsChk = Nothing

'=================================================

What should I do to fix it?
 
You would need to provide the value of the parameter to the query before you
open the recordset. This is commonly done in code.

However, for your situation, I would not open a recordset. Instead, I would
use the DCount function to test the query. Much simpler code.

If DCount("*", "qryGroupSearchResults") > 0 Then
DoCmd.OpenForm "frmGrpSearchResults"
Else
MsgBox "There are no subscribers currently using group #: " &
Me.cmbGrpSearch, vbInformation, "No Data Found!"
End If
 
Back
Top