Link to home
Start Free TrialLog in
Avatar of Greg-C
Greg-C

asked on

Use VBA to sort a continuous Access form by different fields

tblTrans includes fields: dateTrans, amtTrans and typeTrans.  tblTrans contains history-to-date data (multiple years).  

A continuous form, frmTransDetail, opens when the user has specified what date range of transaction detail from tblTrans the user wishes to display, using a range-selection popup form.

Form, frmTransDetail is bound to a query (qryTransDetail) which constrains the range of data via "between getStartDate() and getEndDate()" in its date criteria property, which are functions called from a wrapper module used to store these specs.

By default, the data is ordered by the transDate field; however, often the user must right-click the typeTrans or amtTrans fields to select "sort ascending/descending" to re-order the records.  I would like to provide an OptionGroup to automate this.

Do I re-configure the query (strSQL = ". . .; doCmd.runSQL strSQL) and requery the form or would it be better to bind the form to tblTrans (not qryTrans), using =getStartDate() and =getEndDate() in its filterOn property and alter the orderBy property at the table level?

I beleive my questions has 2 parts: (1) What is the best way to limit a form on a value range of one of its controls [filtered table or query from that table) and (2) how can VBA  say, on a button  re-sort the displayed records similar to the header buttons in MS Dialogs resort the listing.

Thanks,
GregC
Avatar of Greg-C
Greg-C

ASKER

I have been fooling around with this and believe that I was looking for a more complicated solution than required.
I've done what I needed, using the query, by executing this code:
    Me.OrderBy = "tblTrans.transType"
    Me.Requery
I'll leave the question open for alternate solutions.
Thanks,
GregC
 
ASKER CERTIFIED SOLUTION
Avatar of Greg-C
Greg-C

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial