Object Required Error

S

SlowLearner

First, Thanks for looking at this

Can't see why the following code returns "Object
Required" error. I have checked variable types and field
names several times.

Dim ActType() As Long, AcctNumber() As Long, I As Integer

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAccounts", dbOpenDynaset)

Command = "Select * From tblAccounts"

rs.Requery
rs.MoveLast
rs.MoveFirst

'Redim the array
ReDim ActType(rs.RecordCount - 1)
ReDim AcctNumber(rs.RecordCount - 1)

I = 0
'Loop through the fields and assign values
For I = 0 To rs.RecordCount - 1
ActType(I) = rs.Fields("AccountType").Value
AcctNumber(I) = rs.Fields("AccountNumber").Value
rs.MoveNext
Next I

'close the recordset connection to the table
rs.Close
Set rs = Nothing


Any Suggestions?
 
D

Dirk Goldgar

SlowLearner said:
First, Thanks for looking at this

Can't see why the following code returns "Object
Required" error. I have checked variable types and field
names several times.

Dim ActType() As Long, AcctNumber() As Long, I As Integer

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAccounts", dbOpenDynaset)

Command = "Select * From tblAccounts"

rs.Requery
rs.MoveLast
rs.MoveFirst

'Redim the array
ReDim ActType(rs.RecordCount - 1)
ReDim AcctNumber(rs.RecordCount - 1)

I = 0
'Loop through the fields and assign values
For I = 0 To rs.RecordCount - 1
ActType(I) = rs.Fields("AccountType").Value
AcctNumber(I) = rs.Fields("AccountNumber").Value
rs.MoveNext
Next I

'close the recordset connection to the table
rs.Close
Set rs = Nothing


Any Suggestions?

What is "Command", and where is it defined? My guess is that the name
Command is being interpreted as something that requires an object
qualifier.

Incidentally, I don't see what this line:
rs.Requery

could be accomplishing, since you've just opened the recordset.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top