p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

vba_access thread: DAO.Index in descending order by code

Message #1 by "Chris Sperandeo" <csperandeo@h...> on Wed, 11 Jul 2001 05:50:32
Hi Chris,
I don't know how to sort an index in Descending order with DAO but I do 
know how to do it with SQL.  

Dim strSQL AS String

strSQL = ""
strSQL = strSQL & "SELECT [Table].Field1, [Table].Field2, [Table].Field3, "
strSQL = strSQL & "FROM [Table] "
strSQL = strSQL & "ORDER BY [Table].Field1"

The SQL Statement above sorts Field1 in Ascending order and the SQL 
Statement below sorts Field1 in Descending order.

Dim strSQL AS String

strSQL = ""
strSQL = strSQL & "SELECT [Table].Field1, [Table].Field2, [Table].Field3, "
strSQL = strSQL & "FROM [Table] "
strSQL = strSQL & "ORDER BY [Table].Field1 DESC"

After using one of the SQL Statements above you can then change the record 
source for the form by using the line of code below and the records will 
be sorted immediately.  You will not even have to refresh the form or 
databaseWindow or requery the SQL Statement.

Me.RecordSource = strSQL 

Hope this is what you need.

> There is probably a very simple answer for this (there always is) but I 
> can't find it anywhere.  My VB code creates tables with fields and 
> indexes.  I can't seem to find out how to code for indexes in descending 
> order.   I have the following code ( in brief):
>      Set inx = tdf.CreateIndex("PrimaryKey")
>      inx.Primary = True
>      inx.Unique = True
>      Set fld = inx.CreateField("Date")
>      inx.Fields.Append fld
>      tdf.Indexes.Append inx
>      dbs.TableDefs.Append tdf
> It creates tables, fields and indexes fine but I can't find the property 
> that alters sort order of indexes.  (inx.?????)
> Hope someone can help,
> Thanks in advance,
> Chris

  Return to Index