two sorts VBA, how?

  • Thread starter Thread starter Martin
  • Start date Start date
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
 
-----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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top