Hi,
I am needing some help with the code below. It is not filtering what I need
it to and not sure what to do.
I have two comdo boxes that I have the user clicking on to filter the form.
Dim strlistlookup As String
Dim strstkidlookup As String
strlistlookup = cmblistlookup.Value
strstkidlookup = cmbstkidlookup.Value
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
DoCmd.OpenForm "frmcounts", , , "STATUS<>'Complete' "
Me.Form.Filter = (LISTTYPE = strlistlookup)
Me.Form.Filter = (MAXSTKID = strstkidlookup)
Me.Form.FilterOn = True
Thanks in advance for your help!
Aaron
|
|
0
|
|
|
|
Reply
|
Utf
|
5/10/2010 4:41:01 PM |
|
Aaron wrote:
>I am needing some help with the code below. It is not filtering what I need
>it to and not sure what to do.
>I have two comdo boxes that I have the user clicking on to filter the form.
>
>Dim strlistlookup As String
> Dim strstkidlookup As String
>
> strlistlookup = cmblistlookup.Value
> strstkidlookup = cmbstkidlookup.Value
>
> DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
>
> DoCmd.OpenForm "frmcounts", , , "STATUS<>'Complete' "
> Me.Form.Filter = (LISTTYPE = strlistlookup)
> Me.Form.Filter = (MAXSTKID = strstkidlookup)
> Me.Form.FilterOn = True
Note 1) Instead of using the Filter property, you should
use the OpenForm method's WhereCondition argument fo all the
filtering conditions. If you were setting the Filter
property correctly, the Wherecondition string would look the
same.
Note 2) You should not try to use the wizard generated
DoMenuItem stuff, which is a clunky leftover from Access 1
and 2. The RunCommand method was intorduced way back then
as the replacement, but is very rearely the best way to do
anything. A key defficiency of those things is that they
have no way to specify which form they are supposed to
operate on. Instead of those things, hunt around for form
properties or method arguments that do what you need.
From what you've posted, I think the code you 're looking
for would look like:
Dim strWhere As String
If Not IsNull(Me.cmblistlookup) Then
strWhere = strWhere & " And " & Me.cmblistlookup
End If
If Not IsNull(Me.cmbstkidlookup) Then
strWhere = strWhere & " And " & Me.cmbstkidlookup
End If
DoCmd.OpenForm "frmcounts", , , "STATUS<>'Complete' " _
& strWhere
That code assumes that the combo box's bound column is the
selected items numeric foreign key field.
--
Marsh
MVP [MS Access]
|
|
0
|
|
|
|
Reply
|
Marshall
|
5/10/2010 5:22:43 PM
|
|
Aaron -
Three issues I see. After opening the form frmcounts, then you are setting
trying to set the filter of the current form - I assume you want the filter
on the newly-opened form? Second, when you use two 'Me.Form.Filter ='
statements in a row, the second one replaces the first. For a filter with
two pieces, you need to create one filter with the AND joiner. Finally,
when building a filter string, you need to pass in the values by adding the
delimeters within the double-quotes and append the values outside of the
double-quotes. It will look more like this:
DoCmd.OpenForm "frmcounts", , , "STATUS<>'Complete' AND " & _
"[LISTTYPE] = '" & strlistlookup & "' AND [MAXSTKID] = '" & _
strstkidlookup & "'")
If you are struggling with this, Dim a string variable and use Debug.Print
to help find the issue, like this:
Dim txtFilter As String
txtFilter = "STATUS<>'Complete' AND " & _
"[LISTTYPE] = '" & strlistlookup & "' AND [MAXSTKID] = '" & _
strstkidlookup & "'"
Debug.Print txtFilter
DoCmd.OpenForm "frmcounts", , ,txtFilter)
--
Daryl S
"Aaron" wrote:
> Hi,
>
> I am needing some help with the code below. It is not filtering what I need
> it to and not sure what to do.
> I have two comdo boxes that I have the user clicking on to filter the form.
>
> Dim strlistlookup As String
> Dim strstkidlookup As String
>
> strlistlookup = cmblistlookup.Value
> strstkidlookup = cmbstkidlookup.Value
>
> DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
>
> DoCmd.OpenForm "frmcounts", , , "STATUS<>'Complete' "
> Me.Form.Filter = (LISTTYPE = strlistlookup)
> Me.Form.Filter = (MAXSTKID = strstkidlookup)
> Me.Form.FilterOn = True
>
>
> Thanks in advance for your help!
> Aaron
|
|
0
|
|
|
|
Reply
|
Utf
|
5/10/2010 5:30:01 PM
|
|
|
2 Replies
340 Views
(page loaded in 0.058 seconds)
Similiar Articles: Filter Form on Combo Variable - microsoft.public.access ...Hi, I am needing some help with the code below. It is not filtering what I need it to and not sure what to do. I have two comdo boxes that I ha... filter with a variable - microsoft.public.windows.powershell ...Multiple report filter using combo box on form - microsoft.public ... Filter Form on Combo Variable - microsoft.public.access ... Filter a List Box Using a Combo Box ... Assigning Variable from Combo Box - microsoft.public.access.forms ...Assigning Variable from Combo Box - microsoft.public.access.forms ... Assign Macro to Combo Box I was wondering if there was a way to assign a macro to a combo box or drop ... Form filter with multi-column combo box in report - microsoft ...How can I generate a report based on a form filter with multi-column combo boxes when the width of the bound column is 0? If this does not work at all, does ... Multiple report filter using combo box on form - microsoft.public ...... You don't need to "relay" the value from form control to VBA variable to > Filter string ... Multiple report filter using combo box on form - microsoft.public ... Filter a ... Filter combobox in function of other combobox from the same form ...SQL of a form ... vba function ... combobox recordsource query using vba function ... Using a VBA Variable to Filter ... ... To Auto Filter i have a form which has 2 combo ... Filter Datasheet based on Combo Box selection - microsoft.public ...Filter form using multiple combo boxes selection - microsoft ... Multiple report filter using combo box on form - microsoft.public ... Filter Datasheet based on Combo Box ... Filter form using multiple combo boxes selection - microsoft ...I am trying to filter the sub form using 3 combo boxes (or may be more) in my main form. I tried few codes but that didn’t work. Here is the sa... filter combo box in subform withe a combo box in main form ...Dependant combo box in subform - microsoft.public.access.forms ... filter combo box in subform withe a combo box in main form ... Hi, I have a form frmJob, with a subform ... error message 91 Object variable or With block variable not set ...... below and each time I open the form I get this error message: "91 Object variable ... Supply A FieldName Property to filter ... Recordset.Clone I don't think combo ... Filter Form on Combo Variable - microsoft.public.access ...Hi, I am needing some help with the code below. It is not filtering what I need it to and not sure what to do. I have two comdo boxes that I ha... filter form based on combo boxfilter form based on combo box ... form with a drop down of names to filter another form with ... If you declare Strfilter as a Public Variable ... Chapter 3: Using Forms to Collect, Filter, and Display InformationYou don't have to use a variable to open a form. The following line of code ... boxes on a form display suggested values in drop-down combo boxes in the Filter By Form ... Using MS Access: Filtering on a Form, variable criteria, combo boxesvariable criteria, combo boxes, combo box: Frankly, I think you are better off training the users to use Filter by Form. You need to step through your code and make ... Using a VBA Variable to Filter a Query in Access 2007Creating Combo Boxes in Access 2007 that Allow ... function that exposes the value of each variable for which you need to filter a query. (If you still prefer to use the form ... 7/26/2012 1:36:58 PM
|