I
I H Naqvi
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
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