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

Trying to Filter a form 3

Status
Not open for further replies.

bubba100

Technical User
Nov 16, 2001
493
US
Hi all. I am using faq702-777 as a guide. My form has 2 combo boxes and 2 subforms. There is a button that opens another form that will have several checkboxes that will allow the user to select 1 filtering critera. There is one unbound textbox for them to enter the critera. The following the code so far that doesn't filter.

Dim strFilter As String
strFilter = ""
If ChkAcctNum = -1 Then
strFilter = Me![txtSearch].Value
End If
If Len(strFilter) Then
[Forms]![frmBilShet].Filter = "txtAcctNum = '" & strFilter & "'"
[Forms]![frmBilShet].FilterOn = True
End If

Stepping thru, on the FilterOn line a messagebox popups asking for parameter in txtAcctNum. Even if I enter the value again it does not apply the correct filter. I can filter the form by right clicking on the textbox. When as I going wrong? Thanks in advance.
 
I see you have used a string to check txtacctnum against, try...

[Forms]![frmBilShet].Filter = "txtAcctNum = " & strFilter

or

[Forms]![frmBilShet].Filter = "txtAcctNum = '" & val(strFilter) & "'"

also try debug.print [Forms]![frmBilShet].Filter with the immediate window open to see what is being put into the fiter.


Ian Mayor (UK)
Program Error
Always make your words sweet and nice. Because you never know when you may have to eat them.
 
Is txtAcctNum the name of a control? You must use the name of a field from the underlying query or table.
 
Code:
If ChkAcctNum = false and isnull([txtSearch]) = false Then
    [Forms]![frmBilShet].Filter = "fieldnametxtAcctNumIsBoundTo = '" & [txtSearch] & "'"
    [Forms]![frmBilShet].FilterOn = True
End If
As remou says the txtacctnum should be a field. can't recall if -1 is false or true . Amend accordingly.

Ian Mayor (UK)
Program Error
Always make your words sweet and nice. Because you never know when you may have to eat them.
 
can't recall if -1 is false or true
0 is False, any other value is True.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Again, you have pointed me toward the error of my ways. Maybe THIS time I'll remember.

Many thanks.

A star to you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top