Newbie help with "set" command please.

N

newguy

I'm trying to run a loop withing a public function.
Do While Not Myrecordset.EOF
Myrecordset.MoveNext
"Calculations Code"
Loop

After my first error, I declared Myrecordet:
Dim Myrecordset As Recordset

Which brings me to my second error and where I am stuck:
"Object variable or With block variable not set."

Doing some research I founnd I need to use the "set"
command. But, I have no idea what to set Myrecordset to.
Myrecordset is pointing to a subform, in case that
matters. I've been stuck on this for several days so any
help would be appreciated. Thank you
 
P

Pavel Romashkin

You say that Myrecordset is pointing at the subform, but I noticed no
evidence that you specified this in your code. You need to specify what
the Myrecordset is:

Dim MyRST as DAO.Recordset
Set MyRST = Forms!MyForm.Subform.Form.Recordset

After this, MyRST is pointing to the recordset that you want to work
with, and now you can do what you originally have planned - loop, etc.
Good luck,
Pavel
 
R

Ronald W. Roberts

newguy said:
I'm trying to run a loop withing a public function.
Do While Not Myrecordset.EOF
Myrecordset.MoveNext
"Calculations Code"
Loop

After my first error, I declared Myrecordet:
Dim Myrecordset As Recordset

Which brings me to my second error and where I am stuck:
"Object variable or With block variable not set."

Doing some research I founnd I need to use the "set"
command. But, I have no idea what to set Myrecordset to.
Myrecordset is pointing to a subform, in case that
matters. I've been stuck on this for several days so any
help would be appreciated. Thank you
Dim db as database
Dim rs as recordset
Set db = CurrentDB
Set rs = db.OpenRecordset("My_TableName_In_The_CurrentDB")
rs.MoveFirst
Do While Not rs.EOF
"Calculations Code"
rs.MoveNext
Loop

Read help or search the Internet for examples, mvps.org is a good place
to start.
Your use of Myrecordset is just a variable name assigned to a record set
object,
just as the use of rs is or db. You have not told Access or Jet what
Table you wish to
read. For that matter, you have also not told Access or Jet which
database you
wish to process.

The term CurrentBD means and tables or linked tables within the mdb you
are working
with. This implies you can process more than one database in a given
Access application
other than the Current Database.

Using your names, you would have this.
Dim db as database
Dim Myrecordset as recordset
Set db = CurrentDB
Set Myrecordset = db.OpenRecordset("My_TableName_In_The_CurrentDB")
Myrecordset.MoveFirst
Do While Not Myrecordset.EOF
"Calculations Code"
Myrecordset.MoveNext
Loop

Your variable name is much too long and has no meaning. In time you
would have
found this out. Instead of using rs for recordset, you could do
something like this.

tblCustomerMaster

Dim db as Database
Dim CM as recordset
Set db = CurrentDB
Set CM = db.OpenRecordset("tblCustomerMaster")

Ron
 

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