[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
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
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,
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)
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.