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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filters

Status
Not open for further replies.

kmayo503

MIS
Jun 21, 2003
70
US
can you have more than two filters on one form? i have one and i need to add two more. when i added the second filter it popups to ask for the info ok, but it says i have syntax error, but the code is written the same as the 1st filter. can anyone help.

Here is the code:

Private Sub cmdFilter_Click()

Dim strFilter As String
strFilter = InputBox("Enter SalesRep #")

If Len(strFilter & "") > 0 Then
DoCmd.ApplyFilter "", "SalesRepNum=" & CLng(strFilter)
End If

End Sub

Private Sub cmdFilter2_Click()
Dim strFilter As String
strFilter = InputBox("Enter Program Code #")

If Len(strFilter & "") > 0 Then
DoCmd.ApplyFilter "", "Program Code=" & CLng(strFilter)
End If

End Sub
 
You can, but you would nest them and the code would be behind only one of the buttons.

Something like:

[tt]Dim strFilter, strFilter2 As String

strFilter = InputBox("Enter SalesRep #")
strFilter2 = InputBox("Enter Program Code #")

If Len(strFilter & "") > 0 Then
DoCmd.ApplyFilter "", "SalesRepNum=" & CLng(strFilter)
If Len(strFilter2 & "") > 0 Then
DoCmd.ApplyFilter "", "Program Code=" & CLng, "SalesRepNum=" & CLng(strFilter2)
End If
Else
DoCmd.ApplyFilter "", "SalesRepNum=" & CLng(strFilter)
End If[/tt]

Didn't try it, but going on theory. Hope this helps.

Jim DeGeorge [wavey]
 
Sorry...I didn't concatenate the double filter properly.

That comma before the SalesRepNum filter is wrong.

Forget my poor attempt at "helping". Sorry.

Jim DeGeorge [wavey]
 
it didn't work. it won't even popup now. is there a better way to do this. i have a form that i need to pull up all data sorted by the salesrep and the program code. i have several programs in one table, but it was recamended that i combine all of my programs to get the pivot tables that i need. any other thoughts?
 
can i put two filter options on one filter button? right now i have 2 buttons. should i only have the one?
 
A filter is similiar to an SQL Where clause, which can contain mulitple criteria. So, 1 filter is all that is needed.

Example.
Me.Filter = "myid = 1 and otherid = 2" etc.....
 
thanks that worked. i hadn't thought about it that way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top