two sorts VBA, how?

M

Martin

I want VBA to open FORM "ABC" and sort by "field1" (fisrtly sort), "field2"
(secondly sort).

How should the VBA sentence be?

Thanks!


Martin
 
A

Amit

-----Original Message-----
From: Martin [mailto:[email protected]]
Posted At: Tuesday, November 29, 2005 1:45 PM
Posted To: microsoft.public.access
Conversation: two sorts VBA, how?
Subject: two sorts VBA, how?



I want VBA to open FORM "ABC" and sort by "field1" (fisrtly sort), "field2"
(secondly sort).

How should the VBA sentence be?

Thanks!


Martin
 
A

Albert D.Kallal

You do realize that for general sorting, you should base the form on a
query..and thus you don't need to set the sort order, or even use any code.

so, as a general rule...use a query with the order set for the form..

As for using code?

There are two approaches that come to mind

You ca set the forms query directly in code. like:

dim strF as string
dim strSql as string

strF = "frmCustomers" ' name of form to open
strSql = "select * from tblCustomers order by Field1, Field2"

docmd.OpenForm strF
forms(strF).RecordSource = strSql


The 2nd approach that come to mind is using the forms "order by" feature

dim strF as string

strF = "frmCustomers" ' name of form to open
docmd.OpenForm strF

forms(strF).OrderBy = "field1, Field2"
forms(strF).OrderByOn = true
 
A

Amit

Testing once again

-----Original Message-----
From: Amit
Posted At: Tuesday, November 29, 2005 3:01 PM
Posted To: microsoft.public.access
Conversation: two sorts VBA, how?
Subject: re: two sorts VBA, how?


-----Original Message-----
From: Martin [mailto:[email protected]]
Posted At: Tuesday, November 29, 2005 1:45 PM
Posted To: microsoft.public.access
Conversation: two sorts VBA, how?
Subject: two sorts VBA, how?



I want VBA to open FORM "ABC" and sort by "field1" (fisrtly sort), "field2"
(secondly sort).

How should the VBA sentence be?

Thanks!


Martin
 
Top