Object requred Error

M

Maracay

Hi guys,

I have this code, basically what I want is to move from my actual recordset
(rs) to the table "tblMainDataAnalysis†some data, this is my code but I keep
getting the error “Object Requiredâ€, but doesn’t specify in what line is the
error been generated, if someone knows what is this about I will appreciate
it.

Thanks

Private Sub CommAnalyze_Click()
On Error GoTo Err_handler
Dim rs As Recordset
Dim rsa As Recordset
Set rs = Recordset
Set rsa = db.OpenRecordset("tblMainDataAnalysis", dbOpenDynaset)

rs.MoveFirst
Do Until rs.EOF
nLenAddress = Len(address)
nLenAddress2 = Len(address2)
nLenAddress3 = Len(address3)

If nLenAddress > 60 Or nLenAddress2 > 60 Or nLenAddress3 > 60 Then
MsgBox Nz(nLenAddress)
MsgBox Nz(nLenAddress2)
MsgBox Nz(nLenAddress3)
rsa.AddNew
rsa!AnalysisID = 1
rsa!RecordNumber = ListOrder
rsa!address = address
rsa!address2 = address2
rsa!address3 = address3
rsa.Update
rsa.Bookmark = rsa.LastModified
End If

rs.MoveNext
Loop

sExit:
Set rst = Nothing
Me.Requery
Exit Sub

Err_handler:
MsgBox Err.Description
 
J

Jeanette Cunningham

Hi Maracay,

Your code refers to an object called db in this line

--> Set rsa = db.OpenRecordset("tblMainDataAnalysis", dbOpenDynaset)

Create a variable for db
Dim db as DA0.Database
then use Set db = CurrentDb

----------------
Dim db as DA0.Database
Dim rs As Recordset
Dim rsa As Recordset

Set db = CurrentDb
Set rs = Recordset
Set rsa = db.OpenRecordset("tblMainDataAnalysis", dbOpenDynaset)

'rest of your code here

At the sub exit, you will want to destory the db, the rs and the rsa

sExit:
On Error ResumeNext
Set rs = Nothing
Set rsa = Nothing
Set db = Nothing
Me.Requery
Exit Sub
 
D

Dirk Goldgar

(see comments interspersed)

Maracay said:
Hi guys,

I have this code, basically what I want is to move from my actual
recordset
(rs) to the table "tblMainDataAnalysis†some data, this is my code but I
keep
getting the error “Object Requiredâ€, but doesn’t specify in what line is
the
error been generated, if someone knows what is this about I will
appreciate
it.

Thanks

Private Sub CommAnalyze_Click()
On Error GoTo Err_handler
Dim rs As Recordset
Dim rsa As Recordset
Set rs = Recordset

Are you setting rs to the form's recordset? If so, do you realize that as
you navigate in that recordset, your form will also jump around? You might
prefer to set rs to the form's RecordsetClone:

Set rs = Me.RecordsetClone
Set rsa = db.OpenRecordset("tblMainDataAnalysis", dbOpenDynaset)

Your code neither declares nor instantiates db as a Database object. Have
you done this someplace else, at the module level? If not, you'll need:

Dim db As Database

Set db = CurrentDb

before executing the above line.
rs.MoveFirst
Do Until rs.EOF
nLenAddress = Len(address)
nLenAddress2 = Len(address2)
nLenAddress3 = Len(address3)

If nLenAddress > 60 Or nLenAddress2 > 60 Or nLenAddress3 > 60 Then
MsgBox Nz(nLenAddress)
MsgBox Nz(nLenAddress2)
MsgBox Nz(nLenAddress3)
rsa.AddNew
rsa!AnalysisID = 1
rsa!RecordNumber = ListOrder
rsa!address = address
rsa!address2 = address2
rsa!address3 = address3
rsa.Update
rsa.Bookmark = rsa.LastModified
End If

rs.MoveNext
Loop

sExit:
Set rst = Nothing

You never declared "rst" as anything. I suspect you should be using "rsa"
in the above line, but you ought to close it first:

rsa.Close
Set rsa = Nothing
Me.Requery
Exit Sub

Err_handler:
MsgBox Err.Description

What exactly are you trying to do with this code? It seems to me there is
probably an easier way to do it, whatever it is.
 

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