|
-
Sep 17th, 2009, 01:30 PM
#1
Thread Starter
Lively Member
[RESOLVED] use db names instead of fields terminology
see code below, i define a temp recset with 'human readable' names, add to it with same names, sort it, but can't seem to find the syntax to refer to them as such when i eventually read it out. i tried field names enclosed in [], etc but not finding it so far, there should be some way, yes?
Code:
Set rs1 = New ADODB.Recordset
With rs1.Fields
.Append "url", adChar, 50
.Append "periods1-5", adDouble
.Append "periods2-6", adDouble
.Append "periods3-7", adDouble
.Append "reach", adInteger
End With
rs1.Open , , adOpenDynamic
****build it******
rs1.Sort = "periods1-5 desc"
rs1.MoveFirst
Do Until rs1.EOF
Debug.Print (rs1.Fields(rs1.Fields.Count - rs1.Fields.Count).Value)
Debug.Print (rs1.Fields(rs1.Fields.Count - 4).Value)
rpt.WriteLine rs1.Fields(rs1.Fields.Count - rs1.Fields.Count).Value & "," & _
rs1.Fields(rs1.Fields.Count - 4).Value & "," & _
rs1.Fields(rs1.Fields.Count - 3).Value & "," & _
rs1.Fields(rs1.Fields.Count - 2).Value & "," & _
rs1.Fields(rs1.Fields.Count - 1).Value
rptCnt = rptCnt + 1
rs1.MoveNext
etc
-
Sep 17th, 2009, 01:47 PM
#2
Re: use db names instead of fields terminology
You can access any item in a Collection using either the Index(numeric) or Key(string).
ADO automatically uses the name as a Key to the Fields collection.
Debug.Print rs1.Fields("url").Value, rs1.Fields(0).Value
If you are asking how to print the field names
Debug.Print rs1.Fields("url").Name, rs1.Fields(0).Name
-
Sep 17th, 2009, 04:02 PM
#3
Thread Starter
Lively Member
Re: use db names instead of fields terminology
what i want to do is use the field name to access the data, instead of the very verbose fields syntax, eg to access the field called 'url' i want to use something like rs1.url or rs1.[url], etc, instead of
rs1.Fields(rs1.Fields.Count - rs1.Fields.Count).Value,
its simpler, more readable, less typing etc.
but everything i've tried so far doesn't work,
-
Sep 17th, 2009, 04:06 PM
#4
Re: use db names instead of fields terminology
The valid syntaxes for referring to the field of a recordset are:
Code:
rs1!url
rs1("url")
rs1("url").value
rs1.fields("url")
rs1.fields("url").value
The first is not apt for 'invalid' names (ones which contain non-alphanumeric characters, or start with a number)
-
Sep 17th, 2009, 05:48 PM
#5
Thread Starter
Lively Member
Re: [RESOLVED] use db names instead of fields terminology
thanks very much si, you udamon
its embarrassing that all those work and i didn't get any one of them.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|