Form built on Table: How to sort with VBA or ??

  • Thread starter Thread starter Will
  • Start date Start date
W

Will

If I build a Form on a Table... say tblCities...

How can I sort the cities without making a query?

(I'm ending up with so many queries that I can't keep them straight!)

I'm guessing I'll have to do the SQL in the VBA code that creates the
form... right?

If so can anyone give me a simple example to use as a reference?

thanks for the help.
 
Just put the SQL statement into the RecordSource property of your form.

You can reassign the RecordSource to change the sort order, e.g.:
Me.RecordSource = "SELECT tblCities.* FROM tblCities ORDER BY State,
City;"

Alternatively, you could just set the OrderBy property of the form:
Me.OrderBy = "State, City"
Me.OrderByOn = True
 
Will said:
If I build a Form on a Table... say tblCities...

How can I sort the cities without making a query?

(I'm ending up with so many queries that I can't keep them straight!)

You do NOT NEED to create a separate query for the form.

You can build the query right in the form, and it will save for you. (this
does NOT make a query in the query list).

Just bring up the form in design mode, and view the forms property sheet.
(data tab). Now, just click the table name you have. Now, clickon the [...]
that appears to the right. You will be asked to invoke the query
builder....and that query you use can then set the sort order.
I'm guessing I'll have to do the SQL in the VBA code that creates the
form... right?

No, you don't need the above.
 

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

Back
Top