Field order in the Querydef

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have query that basically sorts a single table. The underlying table has
fld1, fld2 and fld3. The query output not only sorts the rows but also
changes the order of the coulmns so that it is left to right, fld2, fld3,
fld1.

Now, using VBA when I spin through the querydef the order is still in fld,1
fld,2 fld3 sequence!!

So querydefs.field(0).name = fld1. I want it, and expected it to be fld2.

How do I accomplish this?

Thanks, James
 
Post the query's SQL statement and the code that you're using to get the
querydef.
 
The order of fields displayed in a query depends on several factors when
the query is written and saved. Check Help from the VB editor on the
OrdinalPosition and ColumnOrder properties of fields in a QueryDef.

Basically, the fields collection is a bucket of fields. If you know the
names of the fields, why don't you reference them by name (meaningful
index) rather than what ammounts to a meaningless/undependable index?

use: querydefs.fields("fld2")

instead of: querydefs.fields(0) 'hoping that the fields have not been
reordered, hidden, renamed, changed since you last found out what index
0 is.

I suppose you could rebuild querydefs adding the fields in the order you
prefer and using OrdinalPosition, but it seems like a gamble to me.

HTH,

Kevin
 
Back
Top