Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a "remove filter" cmd button

Status
Not open for further replies.

vanlanjl

Programmer
Jan 14, 2009
93
0
0
US
I have created a form that contain two combo boxes and two cmd buttons. The idea of the form is that the user will select a search parameter from each combo box then will click the first cmd button "cmdCreateReport". Upon doing so it open a report based of the search criteria.

My problems seems to lay with the seconf cmd button :
cmdRemoveFilter
Code:
Private Sub cmdRemoveFilter_Click()
    On Error Resume Next
' Switch the filter off
    Reports![tblContacts].FilterOn = False
End Sub

also here is te code i used for cmdCreateReport
Code:
strWhere = "1=1 "
If Not IsNull(Me.cboModel) Then
  strWhere = strWhere & " AND [ModelName] =""" & Me.cboModel & """ "
End If
If Not IsNull(Me.cboLocationCode) Then
  strWhere = strWhere & " AND [LocationCode] =""" & Me.cboLocationCode & """ "
End If

DoCmd.OpenReport "tblContacts", acPreview, , strWhere
End Sub

So here is the issue:
I open the form and select my parameters and click on cmdCreateReport and it opens the report correctly. I then click the cmdRemoveFilter button and the report then will show allsearch parameters possable. I assumed that if I were to then go back and change the search parameters and click cmdCreateReport a second time it would then excute properaly but instead the report stays as it was. So how do I make it where I can keep changing the filter processand make the report to produce the search each time?
 
I do a lot of forms with multiple parameters. One of the things I do is set up a option buttons next to the combo boxes. Selecting it activates those parameters, deselecting it turns off those parameters. Create a public function that sets up your variables (I like to use Case statements depending on the type of combo box) (samples taken from my booklist program) - such as:

Public Function varFilter()
Dim FilterOpt As Integer 'filter option group
Dim cmbLib As Integer 'select library

cmbLib = Me.cmbSelLib
FilterOpt = Me.cmbMoreOptions 'Additional Filters

If Me.Option24 = True Then 'add optional filters

Select Case FilterOpt
Case 1
varFilter = varFilter & " and [Booktype] = '" & Me.cmbBooktype & "'"
Case 2
varFilter = varFilter & " and [Author] = '" & Me.cmbAuthor & "'"
Case 3
varFilter = varFilter & " and [Series Name] = '" & Me.cmbSeries & "'"
Case 4
varFilter = varFilter & " and [dateread] >= #" & Me.Starting_Date & "# and [dateread] <= #" & Me.EndingDate & "#"
End Select
End If

Then you set up your button to open your report using if statements (ie):

If Me.cmbSelLib = 6 And Me.Option24 = False And Me.optNextRead = False Then
DoCmd.OpenReport stDocName, acPreview, , "[Read] = no "
Else
DoCmd.OpenReport stDocName, acPreview, , "[Read] = no and " & varFilter
End If



www.accessbrenda.com
 
 http://img.photobucket.com/albums/v636/MusicLady/booklist5.jpg
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top