M
MikeV06
The below Sub returns 2 columns and 3 records. The open shows Recs = 3. The
If statement to move through the recordset returns the name in the first
row but does not move through the next 2 rows. Evidently it thinks it is
EOF and quits. I tried Not .EOF, but it also only returned the first row.
What am I doing wrong. I am using Access 2003.
Thank you, Mike.
Public Sub Retrieve_Test_2()
' ADO - ActiveX Data Objects Architecture directly supported.
' Provides a common set of objects across any data engine including
' SQL Server
Dim cnThisConnect As ADODB.Connection
Dim rstCorpNames As ADODB.Recordset
Dim fldEach As ADODB.Field
Dim strSQL As String
Dim CName As String
Dim Cnt, Recs
Set cnThisConnect = CurrentProject.Connection
Cnt = 1
pstrco = "'1000000001'"
Set rstCorpNames = New ADODB.Recordset
strSQL = "SELECT [tblCorp Name].Corp, " & _
"[tblCorp Name].CorpName FROM [tblCorp Name]" & _
"ORDER BY [tblCorp Name].Corp"
rstCorpNames.Open strSQL, _
cnThisConnect, adOpenKeyset, adLockOptimistic, adCmdText
Recs = rstCorpNames.RecordCount
MsgBox ("Record Count " & Recs)
MsgBox ("rstCorpNames(1) " & rstCorpNames.Fields(1).Name)
For Each fldEach In rstCorpNames.Fields
MsgBox fldEach.Name
Next
rstCorpNames.MoveFirst
If Cnt < Recs Then
CName = rstCorpNames!CorpName
MsgBox ("CorpName = " & CName)
rstCorpNames.MoveNext
Cnt = Cnt + 1
MsgBox ("Cnt & Recs = " & Cnt & " " & Recs)
End If
rstCorpNames.Close
Set rstCorpNames = Nothing
End Sub
If statement to move through the recordset returns the name in the first
row but does not move through the next 2 rows. Evidently it thinks it is
EOF and quits. I tried Not .EOF, but it also only returned the first row.
What am I doing wrong. I am using Access 2003.
Thank you, Mike.
Public Sub Retrieve_Test_2()
' ADO - ActiveX Data Objects Architecture directly supported.
' Provides a common set of objects across any data engine including
' SQL Server
Dim cnThisConnect As ADODB.Connection
Dim rstCorpNames As ADODB.Recordset
Dim fldEach As ADODB.Field
Dim strSQL As String
Dim CName As String
Dim Cnt, Recs
Set cnThisConnect = CurrentProject.Connection
Cnt = 1
pstrco = "'1000000001'"
Set rstCorpNames = New ADODB.Recordset
strSQL = "SELECT [tblCorp Name].Corp, " & _
"[tblCorp Name].CorpName FROM [tblCorp Name]" & _
"ORDER BY [tblCorp Name].Corp"
rstCorpNames.Open strSQL, _
cnThisConnect, adOpenKeyset, adLockOptimistic, adCmdText
Recs = rstCorpNames.RecordCount
MsgBox ("Record Count " & Recs)
MsgBox ("rstCorpNames(1) " & rstCorpNames.Fields(1).Name)
For Each fldEach In rstCorpNames.Fields
MsgBox fldEach.Name
Next
rstCorpNames.MoveFirst
If Cnt < Recs Then
CName = rstCorpNames!CorpName
MsgBox ("CorpName = " & CName)
rstCorpNames.MoveNext
Cnt = Cnt + 1
MsgBox ("Cnt & Recs = " & Cnt & " " & Recs)
End If
rstCorpNames.Close
Set rstCorpNames = Nothing
End Sub