Hi,
I can't loop through a recordset with the code used below.
The first message box says there are 4 records in the recordset.
The second message box shows all 4 records in rows at once instead of one by one. I mean it don't show me the values in 4 messageboxes.
Then I get the error message "Either bof or eof is true or the current record has been deleted. requested operation requires a current record".
What is the problem? What I want is save each value in the recordset in a variable. How can I achieve that? Can anyone help a beginning VBA user?
Richard
--------------------------------
Dim rst As New ADODB.Recordset
Dim NumRecords, CurrentRecord, var
str = "SELECT tblCosts.Price FROM tblCosts WHERE (((tblCosts.Include)=-1) AND ((tblCosts.Itemno)='" & txtItem.Value & "'));"
rst.CursorLocation = adUseServer
rst.Open str, CurrentProject.Connection, 3, 3
rst.MoveFirst
NumRecords = rst.RecordCount
MsgBox NumRecords & " records."
CurrentRecord = rst.GetString
MsgBox "Current: " & CurrentRecord
Do While Not rst.BOF
var = rst.getstring
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
I can't loop through a recordset with the code used below.
The first message box says there are 4 records in the recordset.
The second message box shows all 4 records in rows at once instead of one by one. I mean it don't show me the values in 4 messageboxes.
Then I get the error message "Either bof or eof is true or the current record has been deleted. requested operation requires a current record".
What is the problem? What I want is save each value in the recordset in a variable. How can I achieve that? Can anyone help a beginning VBA user?
Richard
--------------------------------
Dim rst As New ADODB.Recordset
Dim NumRecords, CurrentRecord, var
str = "SELECT tblCosts.Price FROM tblCosts WHERE (((tblCosts.Include)=-1) AND ((tblCosts.Itemno)='" & txtItem.Value & "'));"
rst.CursorLocation = adUseServer
rst.Open str, CurrentProject.Connection, 3, 3
rst.MoveFirst
NumRecords = rst.RecordCount
MsgBox NumRecords & " records."
CurrentRecord = rst.GetString
MsgBox "Current: " & CurrentRecord
Do While Not rst.BOF
var = rst.getstring
rst.MoveNext
Loop
rst.Close
Set rst = Nothing