Again: Counting of Records Before openning a Form

G

Guest

I asked a question and Steve S has responed but the code still not working.
Its gives an error "Too Few Parameters: Expected 2". Now I m rephasing my
Question.
I have One Control form ("Criteria Building Form"). It has Different text
boxes for user inputs and an Ok button. Second is a Data Form ("Master
Information") Based on query ("Criteria"). I have given two parameters to
Query "Criteria" in query design view/Grid they are as follows:-

Query Fields Criteria
[Living Distance] <Forms![Criteria Building Form].[Distance]
[City Radius] <Forms![Criteria Building Form].[Radius]

When only query runs, it asked for parameters, But when "Criteria Building"
Form is open, then running query from main database window automatically
takes paramters. Now the DataForm"Master Information also uses same
Query"Criteria". When I open Data Form from Criteria Form it Works fine
except when selected Criteria (Combination of Boxes) returns no record. In
this case it returns a totaly blank form showing nothing. I want that if it
happens (Query Cause no record) then msg should be generated that "Criteria
returns no Record" and Focus should return to control form instead of opening
data Form.
I have also sured that Microsoft DAO 3.6 Object Library is selected.

The Code which Steve S gave me is

Dim dbsSecurity As DAO.Database
Dim rstCriteria As DAO.Recordset

Dim CountR As Long
Dim stDocName As String
Dim stLinkCriteria As String


Set dbsSecurity = CurrentDb
Set rstCriteria = dbsSecurity.OpenRecordset("Criteria")
'Where Criteria is a valid Query Name

'CountR will be:
' zero if no records
' one if records returned
CountR = rstCriteria.RecordCount

' close objects
rstCriteria.Close
dbsSecurity.Close

'destroy objects
Set rstCriteria = Nothing
Set dbsSecurity = Nothing


If CountR = 0 Then
MsgBox "Selected Criteria Returns No Record"
Else
stDocName = "Build Criteria1"
DoCmd.OpenForm stDocName

'DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
 
T

tina

since the Criteria query is a query object saved in the database, it might
be easier to simply use a DCount() function on it, rather than opening a
recordset. try something along the lines of

If DCount(1, "Criteria") < 1 Then
MsgBox "Criteria returns no Record"
Else
<put here your "open form" code>
End If

hth
 

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