[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

recordset.recordcount always shows -1

My record set always returns a -1 when I enter it as a query it returns records.  Why would it not register records in the recordset and register them in the query?
Dim cn As New ADODB.Connection
    Set cn = CurrentProject.Connection
 
    Dim rs As New ADODB.Recordset
    rs.ActiveConnection = cn
 
    rs.Open "SELECT tblDeferalDetails.EventDetailsID, EventDetailsTable.JobReferenceID " & _
            "FROM EventDetailsTable INNER JOIN tblDeferalDetails ON EventDetailsTable.EventID = tblDeferalDetails.EventDetailsID " & _
            "WHERE (((EventDetailsTable.JobReferenceID)= '16080011'));"
    rs.MoveFirst
    Debug.Print rs.RecordCount

Open in new window

0
ClaudeWalker
Asked:
ClaudeWalker
1 Solution
 
Ashish PatelCommented:
Now try with this.



Dim cn As New ADODB.Connection
    Set cn = CurrentProject.Connection
 
    Dim rs As New ADODB.Recordset
    rs.ActiveConnection = cn
    rs.CursorLocation = adUseClient
   rs.CursorType = adOpenStatic
 
    rs.Open "SELECT tblDeferalDetails.EventDetailsID, EventDetailsTable.JobReferenceID " & _
            "FROM EventDetailsTable INNER JOIN tblDeferalDetails ON EventDetailsTable.EventID = tblDeferalDetails.EventDetailsID " & _
            "WHERE (((EventDetailsTable.JobReferenceID)= '16080011'));"
    rs.MoveFirst
    Debug.Print rs.RecordCount

Open in new window

0
 
mdouganCommented:
Use a cursor type that allows you to MoveLast first, then MoveFirst (I forget what the other options are).  The problem is that the cursor hasn't fetched all the data yet, so, it doesn't know how many records there are.  If you MoveLast, then MoveFirst, it will have retrieved all the data and then your recordcount should be OK.
0
 
chikenheadCommented:
set nocount off

run that statement
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now