My table has n fields, named fld1, fld2, fld3,....fldn
I want to loop through them ..
for i=1 to n
strF="fld" & str(i)
rec.edit
rec!strF = .....
Of course, this doesn't work. How do I get round it?
Simple change in syntax should do the trick. Try the following:
dim strF as string
for i=1 to n
strF="fld" & str(i)
rec.edit
rec(strF) = .....
rec.update
etc.
I assume that you're opening the recordset appropriately, though you're not showing any of that in your snippet.
Use the bracket syntax as illustrated, instead of the bang syntax (ie. !fieldname) if you are using a variable instead of a hard coded fieldname.
Generally speaking, you could use rec("fld1" or rec!fld1 interchangably.
Hope this answers your question,
Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
You can have access to the fields for any recordset like this:
DIM DB AS DATABASE,RS AS RECORDSET,N AS INTEGER,ST
SET DB=CURRENTDB
SET RS=DB.OPENRECORDSET("<<TABLE NAME OR SQL STATEMENT>>"
FOR N=0 TO RS.FIELDS.COUNT-1
ST=RS.FIELDS(N).NAME 'IF YOU WANT FIELD'S NAME OR
ST=RS.FIELDS(N).VALUE 'IF YOU WANT FIELD'S VALUE OR
RS.EDIT 'IF YOU WANT EDIT RECORD
RS.FIELDS(N)=<<ANY VALUE>>
RS.UPDATE
NEXT N
RS.CLOSE
SET RS=NOTHING
DB.CLOSE
SET DB=NOTHING
GOOD LUCK
GNIKOL
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.