By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,775 Members | 2,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,775 IT Pros & Developers. It's quick & easy.

ApplyFilter methodology

P: n/a
I am attempting to use the ApplyFilter command on a form in access and
I am having some questions.

Basically I have a form inwhich I select three things that constitute
a key for each item.
1) Status Type
2) Department Number
3) Vendor Name

My form then feeds into a query which selects the VendorKey based on
all of the informaiton entered on the forms.

I want to use this query to bring up the VendorKey for editing,
similar to what they do in one of the example databases and am having
difficulty with the syntax. My ApplyFilter command looks like this.

Docmd.ApplyFilter , "txt_VendorKey = VendorKey"

Where txt_VendorKey is the name of the text box that my Key is in.
VendorKey is the name of the query inwhich I select the VendorKey that
I want to use to filter my form.

Thank you in advance!!
-michelle
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On your form (Form Header section?), place 3 text boxes where the user can
enter values to filter on, and a pair of command buttons to apply and remove
the filter.

This example shows how to set the filter based on any combination of entries
from the 3 boxes:

Private Sub cmdApplyFilter_Click
Dim strWhere As String
Dim lngLen As Long

If Me.Dirty Then 'Save first.
Me.Dirty = False
End If

'Look at the text boxes where the user entered something.
If Not IsNull(txtFindStatusType) Then
strWhere = strWhere & "([Status Type] = " & _
Me.txtFindStatusType & ") AND "
End If
If Not IsNull(txtFindDept) Then
strWhere = strWhere & "([Department Number] = " & _
Me.txtFindDept & ") AND "
End If
If Not IsNull(txtFindVendor) Then
strWhere = strWhere & "([Vendor Name] = """ & _
Me.txtFindVendor & """) AND "
End If

'Remove the trailing " AND ", and see what's left.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria"
Else
Me.Filter = Left(strWhere, lngLen)
Me.FilterOn = True
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Michelle Dennard" <mi**************@homedepot.com> wrote in message
news:2f**************************@posting.google.c om...
I am attempting to use the ApplyFilter command on a form in access and
I am having some questions.

Basically I have a form inwhich I select three things that constitute
a key for each item.
1) Status Type
2) Department Number
3) Vendor Name

My form then feeds into a query which selects the VendorKey based on
all of the informaiton entered on the forms.

I want to use this query to bring up the VendorKey for editing,
similar to what they do in one of the example databases and am having
difficulty with the syntax. My ApplyFilter command looks like this.

Docmd.ApplyFilter , "txt_VendorKey = VendorKey"

Where txt_VendorKey is the name of the text box that my Key is in.
VendorKey is the name of the query inwhich I select the VendorKey that
I want to use to filter my form.

Thank you in advance!!
-michelle

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.