473,395 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Unsatisfying syntax

With a little help from my friends (that's you) I succeeded to write a
little program.

To access a field in the current record, I simply write its name, for
example:
Value = calculation
Which is, of course, shorthand for
CurrentTable.CurrentRecord.Value = calculation

To access another field, I write
rs.Fields("Value")

Although this works, I really think that such a complicated syntax,
where a string is used instead of an identifier, is pretty improper. I
think that something like
rs.Value
is a lot better

What should it be?
--
Feico
Nov 13 '05 #1
12 1554
Feico wrote:
With a little help from my friends (that's you) I succeeded to write a
little program.

To access a field in the current record, I simply write its name, for
example:
Value = calculation
Which is, of course, shorthand for
CurrentTable.CurrentRecord.Value = calculation

To access another field, I write
rs.Fields("Value")

Although this works, I really think that such a complicated syntax,
where a string is used instead of an identifier, is pretty improper. I
think that something like
rs.Value
is a lot better

What should it be?


If you have an open RecordSet object then you can refer to a field with...

RS!FieldName

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
rs.Collect(Index)
that is:
rs.Collect("NameofField")
or
rs.Collect(3) where 3 is the ordinal position of the field with the
positions beginning at zero.

Nov 13 '05 #3
On Tue, 18 Oct 2005 12:39:58 GMT, "Rick Brandt"
<ri*********@hotmail.com> wrote in comp.databases.ms-access:
If you have an open RecordSet object then you can refer to a field with...

RS!FieldName


I find this much neater than RS.Fields("FieldName")
Unfortunately it didn't work.
Well, you say that a RecordSet must be open.
I executed this:

set db = currentdb
set rs = db.openrecordset("Table")

Doesn't that mean that a RecordSet is open?
--
Feico
Nov 13 '05 #4
"Feico" <fe***@gmsrem0vethis.net> wrote
set db = currentdb
set rs = db.openrecordset("Table")

Doesn't that mean that a RecordSet is open?


It should. Did you move to a Record? When you are doing ADO or DAO, and open
a Recordset, you still have to navigate to the Record you want or iterate
through the Records.

After set rs = db.openrecordset("Table"), you need something like

If Not rs.BOF And rs.EOF Then 'not an empty recordset
rs.MoveFirst 'move to first record
Do Until rs.EOF
<your processing for each record>
rs.MoveNext
Loop

If you are iterating through the records.

And, I am assuming that you are simply using "Table" and "Value" to
represent the actual names. Those are not good names to use; they are Access
reserved words, and can cause confusion.

Larry Linson
Microsoft Access MVP

Nov 13 '05 #5
On Wed, 19 Oct 2005 01:11:29 GMT, "Larry Linson"
<bo*****@localhost.not> wrote in comp.databases.ms-access:
"Feico" <fe***@gmsrem0vethis.net> wrote
set db = currentdb
set rs = db.openrecordset("Table")

Doesn't that mean that a RecordSet is open?
It should. Did you move to a Record? When you are doing ADO or DAO, and open
a Recordset, you still have to navigate to the Record you want or iterate
through the Records.

After set rs = db.openrecordset("Table"), you need something like

If Not rs.BOF And rs.EOF Then 'not an empty recordset
rs.MoveFirst 'move to first record
Do Until rs.EOF
<your processing for each record>
rs.MoveNext
Loop

If you are iterating through the records.

And, I am assuming that you are simply using "Table" and "Value" to
represent the actual names. Those are not good names to use; they are Access
reserved words, and can cause confusion.


Actually, the program is this (irrelevant bits removed):

Option Compare Database

Private Sub BTW1_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim inkoopin as Currency

inkoopin = 0

Set db = CurrentDb
Set rs = db.openrecordset("Inkoop")

Do While Not rs.EOF
inkoopin = inkoopin + rs.Fields("Bedrag") '(1)
inkoopin = inkoopin + rs!Bedrag '(2)
rs.MoveNext
Loop

(1) This works, but I dislike the syntax
(2) I like this syntax, but it doesn't work

Error message (translated into English, so the text may be a bit
different): 3265 during execution. Element not found in set.

These instructions: If Not rs.BOF And rs.EOF Then 'not an empty recordset
rs.MoveFirst 'move to first record

are missing in my program, but the table is not empty, and I find that
MoveFirst is automatic.
--
Feico
Nov 13 '05 #6
Feico wrote:
Actually, the program is this (irrelevant bits removed):

Option Compare Database

Private Sub BTW1_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim inkoopin as Currency

inkoopin = 0

Set db = CurrentDb
Set rs = db.openrecordset("Inkoop")

Do While Not rs.EOF
inkoopin = inkoopin + rs.Fields("Bedrag") '(1)
inkoopin = inkoopin + rs!Bedrag '(2)
rs.MoveNext
Loop

(1) This works, but I dislike the syntax
(2) I like this syntax, but it doesn't work

Error message (translated into English, so the text may be a bit
different): 3265 during execution. Element not found in set.


I have always used (2) and never had a problem with it. If I got that error I
would assume it was because I spelled the name of the field incorrectly.

Does rs!Fields!Bedrag work for you?

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #7
On Wed, 19 Oct 2005 11:27:15 GMT, "Rick Brandt"
<ri*********@hotmail.com> wrote in comp.databases.ms-access:
inkoopin = inkoopin + rs.Fields("Bedrag") '(1)
inkoopin = inkoopin + rs!Bedrag '(2) (1) This works, but I dislike the syntax
(2) I like this syntax, but it doesn't work

Error message (translated into English, so the text may be a bit
different): 3265 during execution. Element not found in set.


I have always used (2) and never had a problem with it. If I got that error I
would assume it was because I spelled the name of the field incorrectly.

Does rs!Fields!Bedrag work for you?


Nope, same error message. And of course I checked the spelling of the
name. And it is case insensitive, isn't it?
--
Feico
Nov 13 '05 #8
both of these should work:
inkoopin = inkoopin + rs.Fields("Bedrag") '(1)
inkoopin = inkoopin + rs!Bedrag '(2)

neither version is case sensitive.
i'm guessing that you might get different error messages for each
version, if the field you are after is not in the rs.

try dumping out all the fields in the rs just prior to referencing the
field.

For iCol = 0 To rs.Fields.Count - 1
msgbox(rs.Fields(iCol).Name
Next

Nov 13 '05 #9
On 19 Oct 2005 05:21:46 -0700, Jo**@ViridianTech.com wrote in
comp.databases.ms-access:
try dumping out all the fields in the rs just prior to referencing the
field.

For iCol = 0 To rs.Fields.Count - 1
msgbox(rs.Fields(iCol).Name
Next


Well, it displays the names of all columns in the table.

However, I just made a new discovery. The trouble only occurs when
there are spaces in the name of the column. I replaced these with
underscores and was pretty sure that this ws correct.
inkoopin = inkoopin + rs.Fields("Bed rag") '(space in name)
inkoopin = inkoopin + rs!Bed_rag '(underscore in name)


The latter is not accepted. There is no problem if there is no
space/underscore in the name.
--
Feico
Nov 13 '05 #10
Oh, so the example you first gave was not exactly working (i.e
crashing) code. You're making it harder on us to help you debug.

yes, blanks in the name are bad, don't use them. it messes up all
sorts of stuff. and it won't upsize if you ever intend to convert to
Oracle or Sql Server. you'll have problems the rest of your life with
stored procs and such.

If you're fussy about syntax, you're going to hate this..
I think you'll have to use this...rs![bed rag]

Nov 13 '05 #11
On 19 Oct 2005 08:15:12 -0700, Jo**@ViridianTech.com wrote in
comp.databases.ms-access:
Oh, so the example you first gave was not exactly working (i.e
crashing) code. You're making it harder on us to help you debug.
I'm sorry. In other parts of the syntax spaces should be replaced by
underscores, and I could not imagine that it wouldn't work in other
positions.
If you're fussy about syntax, you're going to hate this..
I think you'll have to use this...rs![bed rag]


Well, after all it solves my problems.

BTW, the program is not about blankets. "Bedrag" is Dutch and means
"amount of money" .
--
Feico
Nov 13 '05 #12
Jo**@ViridianTech.com wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:
Oh, so the example you first gave was not exactly working (i.e
crashing) code. You're making it harder on us to help you debug.

yes, blanks in the name are bad, don't use them. it messes up all
sorts of stuff. and it won't upsize if you ever intend to convert
to Oracle or Sql Server. you'll have problems the rest of your
life with stored procs and such.

If you're fussy about syntax, you're going to hate this..
I think you'll have to use this...rs![bed rag]


Or rs("bed rag") will work, too.

I agree -- no spaces or special characters in field names. It makes
programming much, much easier with no compromise of readability (if
you use upper case to demarcate word divisions).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
22
by: Tuang | last post by:
I'm checking out Python as a candidate for replacing Perl as my "Swiss Army knife" tool. The longer I can remember the syntax for performing a task, the more likely I am to use it on the spot if...
14
by: Sandy Norton | last post by:
If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def...
16
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very...
23
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
4
by: Jeremy Yallop | last post by:
Looking over some code I came across a line like this if isalnum((unsigned char)c) { which was accepted by the compiler without complaint. Should the compiler have issued a diagnostic in this...
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.