Test for records based on query

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....
 
S

Steve Schapel

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
 
G

Guest

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....
 
G

Guest

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....
 

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

Similar Threads


Top