Article ID: 146310
Article Last Modified on 1/19/2007
CompanyName
ContactName
City
Region
Country
Form: Sort Form
---------------------
ScrollBars: Neither
RecordSelectors: No
NavigationButtons: No
PopUp: Yes
BorderStyle: Thin
MinMaxButtons: None
Private Sub Form_Open(Cancel As Integer)
' Opens the report in Design view when the form opens.
DoCmd.OpenReport "Sort Report", acviewDesign
' ("acDesign" in Microsoft Access version 7.0)
DoCmd.Maximize
End Sub
Private Sub Form_Close()
' Closes the report when the form closes.
DoCmd.Close acReport, "Sort Report"
DoCmd.Restore
End Sub
Combo box:
Name: Sort1
RowSourceType: Field List
RowSource: Select [CompanyName], [ContactName], [City], _
[Region],[Country] from Customers
Combo box:
Name: Sort2
RowSourceType: Field List
RowSource: Select [CompanyName], [ContactName], [City], _
[Region],[Country] from Customers
Combo box:
Name: Sort3
RowSourceType: Field List
RowSource: Select [CompanyName], [ContactName], [City], _
[Region], [Country] from Customers
Combo box:
Name: Sort4
RowSourceType: Field List
RowSource: Select [CompanyName], [ContactName], [City], _
[Region], [Country] from Customers
Combo box:
Name: Sort5
RowSourceType: Field List
RowSource: Select [CompanyName], [ContactName], [City], _
[Region], [Country] from Customers
Check box:
Name: Check1
Check box:
Name: Check2
Check box:
Name: Check3
Check box:
Name: Check4
Check box:
Name: Check5
Command button:
Name:Clear
Caption:Clear
OnClick: [Event procedure]
Set the OnClick [Event procedure] to the following:
Private Sub Clear_Click()
Dim intCounter as Integer
For intCounter= 1 To 5
Me("Sort" &intCounter) = ""
Me("Check" &intCounter) = ""
Next
End Sub
Command button:
Name SetOrderBy
Caption SetOrderBy
OnClick: [Event procedure]
Set the OnClick [Event procedure] to the following:
Private Sub SetOrderBy_Click()
Dim strSQL as String, intCounter as Integer
' Build strSQL String.
For intCounter= 1 To 5
If Me("Sort" &intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Sort" &intCounter) & "]"
If Me("Check" &intCounter) = True Then
strSQL = strSQL & " DESC"
End IF
strSQL = strSQL & ", "
End If
Next
If strSQL <> "" Then
' Strip Last Comma & Space.
strSQL = Left(strSQL, (Len(strSQL) - 2))
' Set the OrderBy property.
Reports![Sort Report].OrderBy = strSQL
Reports![Sort Report].OrderByOn = True
End If
End Sub
Additional query words: dynamically
Keywords: kbhowto KB146310