Hi, I am quite new to ado and dao, and by the looks of things, ado is the preferred method (bearing in mind future proofing of applications).
I am trying to prevent a form opening if there are no records, and have tried both ADO and DAO, but cant seem to get it right. Any help appreciated!
************
ADO Method:
************
Dim rs As ADODB.Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Set rs = New ADODB.Recordset
rs.Open "qryContactDetailsSearch"
If rs.EOF And rs.BOF Then
MsgBox ("No records found")
rs.Close
Set rs = Nothing
Else
stDocName = "sfrmSearchResultsContact"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
************
DAO Method:
************
Dim rs As DAO.Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Set rs = CurrentDb.OpenRecordset("qryCompanyDetailsSearch")
If rs.EOF And rs.BOF Then
MsgBox ("No records found")
Else
stDocName = "sfrmSearchResultsCompany"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Set rs = Nothing
I am trying to prevent a form opening if there are no records, and have tried both ADO and DAO, but cant seem to get it right. Any help appreciated!
************
ADO Method:
************
Dim rs As ADODB.Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Set rs = New ADODB.Recordset
rs.Open "qryContactDetailsSearch"
If rs.EOF And rs.BOF Then
MsgBox ("No records found")
rs.Close
Set rs = Nothing
Else
stDocName = "sfrmSearchResultsContact"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
************
DAO Method:
************
Dim rs As DAO.Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Set rs = CurrentDb.OpenRecordset("qryCompanyDetailsSearch")
If rs.EOF And rs.BOF Then
MsgBox ("No records found")
Else
stDocName = "sfrmSearchResultsCompany"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Set rs = Nothing