Here is some example code from one of my databases which may help you. It is based on a table containing fields 'EmployeeID' and 'EmployeeName', but you can use it for any table and any number of sort fields.
First, define two global variables in a module:
Code:
Public stChooserID As String
Public stSortBy As String
Next, create a 'selection form' with three controls:
A Command Button - btnRunReport
Two combo boxes - cmbSortOrder, cmbChooseEmployee
I used the wizard to create cmbChooseEmployee, so it displays a list of all the EmployeeID and EmployeeName values from my table.
cmbSortOrder just contains two values which I typed in:
By ID
By Name
I used the wizard to create the command button as an 'Open Report' button which opens my report. I then changed the click event code for the button:
Code:
On Error GoTo Err_btnRunReport1_Click
Dim stDocName As String
cmbSortOrder.SetFocus
Select Case cmbSortOrder.Text
Case Is = "By ID"
stSortBy = "[EmployeeID]"
Case Is = "By Name"
stSortBy = "[EmployeeName]"
Case Else
MsgBox "Please choose a Sort Order"
Exit Sub
End Select
If IsNull(cmbChooseEmployee) Then
stChooserID = ""
Else
stChooserID = "[EmployeeID]='" & _
cmbChooseApplication & "'"
End If
stDocName = "MyReportName"
DoCmd.OpenReport stDocName, acPreview
Exit_btnRunReport1_Click:
Exit Sub
Err_btnRunReport1_Click:
MsgBox Err.Description
Resume Exit_btnRunReport1_Click
End Sub
Now write this code into the On Open event of the report:
Code:
Private Sub Report_Open(Cancel As Integer)
Me.OrderBy = stSortBy
Me.OrderByOn = True
If stChooserID > "" Then
Me.Filter = stChooserID
Me.FilterOn = True
Else
Me.Filter = ""
Me.FilterOn = False
End If
End Sub
When you test this, you should see this behaviour when you click the 'run report' button:
-- Choose 'By ID' as the sort order, leave the 'Employee Name' combo box blank .... see a list of all Employees, sorted by ID
-- Choose 'By Name' as the sort order, leave the 'Employee Name' combo box blank .... see a list of all Employees, sorted by name
-- Choose an Employee name from the combo box ... see just one record listed, for this Employee
I hope that this will give you some clues ... using this technique you should be able to build a report whicih will list details for one Vendor or all vendors, sorted by any column which you choose.
Bob Stubbs