Setting up a form to Sort a report

  • Thread starter Thread starter Gary Hull
  • Start date Start date
G

Gary Hull

Hello

I need to set up a form that will sort a report in different ways

Maybe use command buttons for each sort.

I am open and any Ideas

Thanks

Gary
 
Gary Hull said:
Hello

I need to set up a form that will sort a report in different ways

Maybe use command buttons for each sort.

I am open and any Ideas

I would suggest setting up a reports dialog form which, when you press the
"preview" command button, stays open but hides itself so that you can use
the names of its controls within the report's code to determine what
field(s) to sort on and in what order. You could use combo boxes for field
name selection and an option group to select sort order.

Unhide the form in the report's close event.

Regards,
Keith.
www.keithwilby.com
 
Gary Hull said:
How do I pass the variable to the report?

You don't need to pass anything. Refer to the form's control names in the
report's open event, for example (untested):

Dim strSQL as String, strSortOrder As String, strFieldName1 as String,
strFieldValue1 as String

If [Forms]![frmMyDialog]![ogrSortOrder] = 1 then strSortOrder = "Asc"
If [Forms]![frmMyDialog]![ogrSortOrder] = 2 then strSortOrder = "Desc"

strFieldName1 = [Forms]![frmMyDialog]![cboField1]
strFieldValue1 = [Forms]![frmMyDialog]![cboValue1]

strSQL = "Select * from qryMyQuery where " & strFieldName1 & " = " &
strFieldValue1
strSQL = strSQL & " Order by " & strFieldName1 & " " & strSortOrder

Me.RecordSource = strSQL

This code isn't the B-all and end-all but it should give you a starter for
ten.

Regards,
Keith.
 

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