Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset

Status
Not open for further replies.

Ragah21

MIS
Apr 17, 2007
17
US
i need some help to correct the below code.

Public Sub Check_Records()

Dim dbs As DAO.Database, qdfCurr As DAO.QueryDef, rst As DAO.Recordset, strSQL As String

Set dbs = CurrentDb

If QueryDefs("NAMEOFMYQRY").Recordset.RecordCount = 0 Then
MsgBox "There are no records to wiew.", vbQuestion, "Error"
End If

End Sub
 
Straight from the Access Help. Looks like you have to OPEN the recordset before you can determine the record count.

Dim dbsNorthwind As Database
Dim rstEmployees As Recordset

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

With dbsNorthwind
' Open table-type Recordset and show RecordCount
' property.
Set rstEmployees = .OpenRecordset("Employees")
Debug.Print _
"Table-type recordset from Employees table"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
rstEmployees.Close

 
How are ya Ragah21 . . .

Use a recordset instead!
Code:
[blue]Public Sub Check_Records()

   Dim dbs As DAO.Database, rst As DAO.Recordset
   Dim Msg As String, Style As Integer, Title As String
   
    
   Set dbs = CurrentDb
   Set rst = dbs.OpenRecordset("NAMEOFMYQRY", dbOpenDynaset)
   DL = vbNewLine & vbNewLine
   
   If rst.BOF Then
      Msg = "There are no records to view!"
      Style = vbInformation + vbOKOnly
      Title = "Error!"
      MsgBox Msg, Style, Title
   End If
   
   Set rst = Nothing
   Set dbs = Nothing
   
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top