rst! - what's that?

  • Thread starter Thread starter Eliezer
  • Start date Start date
E

Eliezer

OK, I've looked all around, but I have no idea what the
heck this line means, and best I can tell its screwing my
module up.

I posted earlier while writing a module for a table with
values such as "abc1, abc2, abc3...". I was (and still am)
trying to write something which will do, simply put,

Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim rst As New ADODB.Recordset
Dim ** all the necessary variables in all their correct
types... integers are integers, strings are strings **
rst.Open "select * from testdata", cnn, adOpenDynamic,
adLockOptimistic
for n = 1 to 50
tempname = "abc" & CStr(n)
if rst(tempname) > 2
** do stuff **
else:
next n

However, when I run this, I get an error:

Run-time error '3265':

Item cannot be found in the collection corresponding to
the requested name or ordinal

What the heck does that mean, and how can I fix it? Thanks
in advance!
 
looks like you try to read field, which does not exist in rst
when you get error - examine the value of tempname var, this can give an
idea
 
Thanks, I didn't know you could do that. It turned out I
was forgetting to reset some values. It works now.

By the way, I got so caught up in my second question I
sort of overshadowed my original question - the on in the
title of this thread. What the heck does "rst!" mean?
 
Short Answer: Shortcut to a field name in the recordset.


Long Answer: When you open a recordset, it is basically
like a table. You have rows and fields. So, in order to
access the EmployeeID field, you would:

rst.Fields("EmployeeID").value

The rst is the recordset you are referencing. It contains
a collection of all the fields in it.

rst.Fields.Count would return the number of fields.

Now, you want a specific field.

rst.Fields("EmployeeID").value

Because Value is the default method, you can leave it off.

rst.Fields("EmployeeID")

Also, the Fields collection is the default property of the
recordset, so you can leave it off:

rst("EmployeeID")

This can easily be rewritten as:

rst!EmployeeID

They are all the same. Just different ways to do it.


Chris Nebinger
 
Back
Top