Article ID: 147143
Article Last Modified on 1/19/2007
CompanyName
ContactName
City
Region
Country
Form: frmFilter
---------------------
ScrollBars: Neither
RecordSelectors: No
NavigationButtons: No
PopUp: Yes
BorderStyle: Thin
MinMaxButtons: None
Width: 2.5"
Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenReport "rptCustomers", A_PREVIEW 'Open Customers report.
DoCmd.Maximize 'Maximize the report window.
End Sub
Private Sub Form_Close()
DoCmd.Close acReport, "rptCustomers" 'Close the Customers report.
DoCmd.Restore 'Restore the window size
End Sub
Combo box:
Name: Filter1
Tag: CompanyName
RowSource: Select Distinct [CompanyName] from Customers Order _
By [CompanyName];
Width: 1.5"
Combo Box:
Name: Filter2
Tag: ContactName
RowSource: Select Distinct [ContactName] from Customers Order _
By [ContactName];
Width: 1.5"
Combo Box:
Name: Filter3
Tag: City
RowSource: Select Distinct [City] from Customers Order By [City];
Width: 1.5"
Combo Box:
Name: Filter4
Tag: Region
RowSource: SELECT DISTINCT Customers.Region FROM Customers _
WHERE(((Customers.Region) Is Not Null)) ORDER BY _
Customers.Region;
Width: 1.5"
Combo Box:
Name: Filter5
Tag: Country
RowSource: Select Distinct [Country] from Customers Order _
By [Country];
Width: 1.5"
Command button:
Name: Clear
Caption: Clear
OnClick: [Event procedure]
Set the OnClick [Event procedure] as follows:
Private Sub Clear_Click()
Dim intCounter as Integer
For intCounter = 1 To 5
Me("Filter" & intCounter) = ""
Next
End Sub
Command Button:
Name: Set Filter
Caption: Set Filter
OnClick: [Event procedure]
Set the OnClick [Event procedure] as follows:
Private Sub Set_Filter_Click()
Dim strSQL as String, intCounter as Integer
' Build SQL String.
For intCounter = 1 To 5
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " _
& " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & _
" And "
End If
Next
If strSQL <> "" Then
' Strip Last " And ".
strSQL = Left(strSQL, (Len(strSQL) - 5))
' Set the Filter property.
Reports![rptCustomers].Filter = strSQL
Reports![rptCustomers].FilterOn = True
End If
End Sub
Command Button:
Name: Close
Caption: Close
OnClick: [Event procedure]
Set the OnClick [Event procedure] as follows:
Private Sub Close_Click()
DoCmd.Close acForm, Me.Form.Name
End Sub
Additional query words: dynamic popup
Keywords: kbhowto KB147143