Test for records based on query

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

Guest

I had to build a query to which a form is bound in order to view data based
on criteria that I could not get to work any other way.

The qurey takes [VehicleNumber] and limits the query to the specific
vehicle, then takes [txtStartDate] and [TxtEndDate] and searches for entries
between these two dates.

What I now want to do, is check to see if there are any records before
running DoCmd.OpenForm.

What I have tried is this:
-----------------------------

Dim stDocName As String
Dim db As DAO.Database
Dim rst As Dao.RecordSet

Set db = Currentdb()
stDocName = "frmDispositionHistory'

--
If & Else If statements here to check that txtStartDate and txtEndDate are
entered
--

Set rst = db.OpenRecordSet("qrySearchDispositions")
If rst.RecordCount > 0 Then
DoCmd.OpenForm stDocName
Exit Sub
Else
MsgBox("blah blah....")
Exit Sub
End If

-----------------------------------------

When I click the button to begin the search, I get an error message :Too few
parameters, expecting 3

Any help is appreciated....
 
Paul,

The "too few parameters" is referring to the form referenced criteria in
the query. There are ways of handling this, but I would prefer in this
instance to do it like this....

If DCount("*","qrySearchDispositions") Then
DoCmd.OpenForm "frmDispositionHistory"
Else
MsgBox("blah blah....")
End If
 
Thanks Steve.

Steve Schapel said:
Paul,

The "too few parameters" is referring to the form referenced criteria in
the query. There are ways of handling this, but I would prefer in this
instance to do it like this....

If DCount("*","qrySearchDispositions") Then
DoCmd.OpenForm "frmDispositionHistory"
Else
MsgBox("blah blah....")
End If

--
Steve Schapel, Microsoft Access MVP

I had to build a query to which a form is bound in order to view data based
on criteria that I could not get to work any other way.

The qurey takes [VehicleNumber] and limits the query to the specific
vehicle, then takes [txtStartDate] and [TxtEndDate] and searches for entries
between these two dates.

What I now want to do, is check to see if there are any records before
running DoCmd.OpenForm.

What I have tried is this:
-----------------------------

Dim stDocName As String
Dim db As DAO.Database
Dim rst As Dao.RecordSet

Set db = Currentdb()
stDocName = "frmDispositionHistory'

--
If & Else If statements here to check that txtStartDate and txtEndDate are
entered
--

Set rst = db.OpenRecordSet("qrySearchDispositions")
If rst.RecordCount > 0 Then
DoCmd.OpenForm stDocName
Exit Sub
Else
MsgBox("blah blah....")
Exit Sub
End If

-----------------------------------------

When I click the button to begin the search, I get an error message :Too few
parameters, expecting 3

Any help is appreciated....
 
Paul B. said:
I had to build a query to which a form is bound in order to view data based
on criteria that I could not get to work any other way.

The qurey takes [VehicleNumber] and limits the query to the specific
vehicle, then takes [txtStartDate] and [TxtEndDate] and searches for entries
between these two dates.

What I now want to do, is check to see if there are any records before
running DoCmd.OpenForm.

What I have tried is this:
-----------------------------

Dim stDocName As String
Dim db As DAO.Database
Dim rst As Dao.RecordSet

Set db = Currentdb()
stDocName = "frmDispositionHistory'

--
If & Else If statements here to check that txtStartDate and txtEndDate are
entered
--

Set rst = db.OpenRecordSet("qrySearchDispositions")
If rst.RecordCount > 0 Then
DoCmd.OpenForm stDocName
Exit Sub
Else
MsgBox("blah blah....")
Exit Sub
End If

-----------------------------------------

When I click the button to begin the search, I get an error message :Too few
parameters, expecting 3

Any help is appreciated....
 
Back
Top