Set adoRecordset = adoCommand.Execute
I am trying to loop though the recordset:
Do While Not adoRecordset.EOF
MsgBox "some text here"
adoRecordset.MoveNext
Loop
The messagebox was not appearing so I assumed the recorset was empty,
however when I added a recordcount. I found the recordset was not empty. So I
checked whether EOF was true: It was. I also checked EOF and it was also
true. My understanding is that if BOF and EOF are both true then the
recordset is empy. Hoow can the recordset be empy if I am getting a
recordcount in the 100s?
MsgBox adoRecordset.RecordCount - returned 1018
MsgBox "BOF = " & adoRecordset.BOF - returned true
MsgBox "EOF = " & adoRecordset.EOF - returned true
Do While Not adoRecordset.EOF
MsgBox "some text here"
adoRecordset.MoveNext
Loop
Set adoRecordset = adoCommand.Execute
With adoRecordset
If .RecordCount = 0 Then
MsgBox "No Records Found"
Else
.MoveLast
.MoveFirst
Do While Not .EOF
MsgBox "some text here"
.MoveNext
Loop
End If
End With
--
Dave Hargis, Microsoft Access MVP
"[I]t is a good practice to fully populate the recordset before you start
using it."
What makes you say that, Dave? The only reason I know of for doing a
.MoveLast, .MoveFirst before processing a recordset is to make the
.RecordCount property accurate. If you don't need to know how many records
were returned before working with them, I can't think of any reason for
adding the extra overhead of forcing all records to be retrieved before
processing the first record.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
That's odd. If the RecordCount can't be determined yet, it's supposed to
have a value of -1, but I can't see why it would be 1018 if .EOF and .BOF
are both true. Would you mind posting the whole code from the point where
you create the Recordset object to the point where you exit the loop?
In DAO, I am with Dirk .. no need to populate (MoveLast) it, unless you want
the .RecordCount property to reflect the number of records contained in the
recordset.
The reason you have to fully populate a DAO recordset for the RecordCount to
reflect the number of records is that, by definition, in DAO the RecordCount
property is the number of records ACCESSED (and DAO populates, or accesses,
the records as they are needed). Where as in ADO, the RecordCount property
is defined as the number of records in the recordset.
--
Brent Spaulding | datAdrenaline | Access MVP
"Dirk Goldgar" <d...@NOdataSPAMgnostics.com.invalid> wrote in message
news:450C904A-53E7-4ADF...@microsoft.com...
--
Brent Spaulding | datAdrenaline | Access MVP
"Breeze" <Bre...@discussions.microsoft.com> wrote in message
news:92260628-9C48-4178...@microsoft.com...
Private Sub Command0_Click()
Dim adoConnection As ADODB.Connection
Dim ADDatabase As Database
Dim adoRecordset As ADODB.Recordset
' Connect to the AD database and create a recordset of all the user accounts
Set ADDatabase = CurrentDb
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on computer objects.
strFilter = "(objectCategory=user)"
' Comma delimited list of attribute values to retrieve.
strAttributes =
"objectGuid,whencreated,sAMAccountName,GivenName,sn,description,department,manager,ou,userAccountControl,accountExpires"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
MsgBox adoRecordset.RecordCount
MsgBox "BOF = " & adoRecordset.BOF
MsgBox "EOF = " & adoRecordset.EOF
Do Until adoRecordset.EOF
MsgBox "Hello"
adoRecordset.MoveNext
Loop
MsgBox "done"
End Sub1
I did try the movelast and movefirst before I posted yesterday, but got an
error message in both cases as essentially the recordset is being reported as
emtpy. I am creating the recordset from AD could it possibly have something
to do with that?
Thanks for the help.
Peter
Private Sub Command0_Click()
MsgBox "BOF = " & adoRecordset.BOF
MsgBox "EOF = " & adoRecordset.EOF