Re: using the .filter command



Bob Barrows [MVP] wrote:
Chris wrote:
Hi everyone, i am have a problem, can anybody please help?

My problem is, I am using a DataGrid that is populated with data,
and I am trying to "filter" it with 2 different criteria's,
EmployeeNumber and date.

Below is the code that I have, but does not work as it comes up with
an error.

How can we help if you don't tell us what the error is?
With Adodc1.Recordset
.Filter = ("EmployeeNumber = " & Val(Text2) And ("EntryDate < " &
DateValue(Text4)))

Was this a copy/paste from your code? or did you introduce a type when retyping it here?
It should be more like this (I suggest assigning the filter string to a variable to make it easier for you to look at the result of your concatenation - is this VB? If so, you can use debug to look at it):

flt_txt = "EmployeeNumber = " & Val(Text2) & _
"And EntryDate < " & DateValue(Text4)
.Filter = flt_txt

However, this may not be the exact string needed because we don't know the data types of the fields involved.

Please anybody able to shed any light on my problem?

The ADO documentation can be read online here: http://msdn2.microsoft.com/en-us/library/ms675532.aspx

Make sure you go read what it says about the Filter property:


Well, I think it *should* be safe to assume that EntryDate is just that.... and needs to be enclosed as such. Even if it isn't a date and it's a string (tisk, tisk), it still needs delimiters on it.
flt_txt = "EmployeeNumber = " & Text2.Text & _
"AND EntryDate < #" & DateValue(Text4.Text) & "#"

If it's a string, or the source was SQL Server, then replace the # with '

-ca
.



Relevant Pages

  • Re: Filtering records on a form using multiple combo boxes
    ... So, then, you will need to build the Where string from that information, ... these 3 combo boxes have command buttons to activate the filtering ... filter the field in the record list box.. ... For the Agent Combo Box, ...
    (microsoft.public.access.forms)
  • RE: Set Filter from Startup form to another form
    ... Private Sub Form_Load ... Dim strPrg As String ... Private Function StartProgramAs String ... Now all that is necessary is to set the filter for each form where you want ...
    (microsoft.public.access.formscoding)
  • Re: Filter for Report not working?????
    ... cno2, cField string ... contFilter DynArrayString ... I surround the value with quotes to make it a string otherwise the filter ... I decided to go with a table in PRIV for the report. ...
    (comp.databases.paradox)
  • RE: Query form coding
    ... What is the record source of the report? ... Dim strSource As String ... ' Remove Filter ... For Each varItem In Me.namelst.ItemsSelected ...
    (microsoft.public.access.formscoding)
  • Re: Filtering records on a form using multiple combo boxes
    ... then build the SQL string with the Where clause in it, ... Allen Browne - Microsoft MVP. ... these 3 combo boxes have command buttons to activate the filtering ... filter the field in the record list box.. ...
    (microsoft.public.access.forms)