Filtering a Form

  • Thread starter Thread starter johnG
  • Start date Start date
J

johnG

Hi

I have a form that displays the relevant info about the
Customers, it is based on a query (QryCustomers).

I want my users to be able to filter the form based on
characters typed into a Textbox for instance:

if the user types: "Carl" in the Textbox I would like to
filter all the records with "Carl" anywhere in the
Customer_Name field to be displayed

When I use the formula:

Like "*[Carl]*"

in the Criteria column of the query it returns the
required records, but when I try to reproduce this in a
VBA module. i.e.

Dim Strfilter as string

Strfilter = "[Customer_Name] Like *[Me.searchName]*"
Me.filter "Strfilter"

I have tried various alternatives using the Ampersand &
and the Sigle quote ' , but each time I seem to get an
error(usaully a syntax error)

can anyone help?
thanks


Ps: I have also tried to create a Recordset but I run
into the same problem the compiler doesn't seem to want
to recognise the wildcard * character. In any case i'm
still trying to figure out how to asign the new recordset
to an opoen form?
 
Concatenate the value from the text box into the string:
Strfilter = "[Customer_Name] Like ""*" & [Me.searchName] & "*"""
 
-----Original Message-----
Concatenate the value from the text box into the string:
Strfilter = "[Customer_Name] Like ""*" & [Me.searchName] & "*"""

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Hi

I have a form that displays the relevant info about the
Customers, it is based on a query (QryCustomers).

I want my users to be able to filter the form based on
characters typed into a Textbox for instance:

if the user types: "Carl" in the Textbox I would like to
filter all the records with "Carl" anywhere in the
Customer_Name field to be displayed

When I use the formula:

Like "*[Carl]*"

in the Criteria column of the query it returns the
required records, but when I try to reproduce this in a
VBA module. i.e.

Dim Strfilter as string

Strfilter = "[Customer_Name] Like *[Me.searchName]*"
Me.filter "Strfilter"

I have tried various alternatives using the Ampersand &
and the Sigle quote ' , but each time I seem to get an
error(usaully a syntax error)

can anyone help?
thanks


Ps: I have also tried to create a Recordset but I run
into the same problem the compiler doesn't seem to want
to recognise the wildcard * character. In any case i'm
still trying to figure out how to asign the new recordset
to an opoen form?


.Your cancatonation does seem to have been accepted now
the the compiler ginine me another error message, it
tells me that:

Me.Filter is an invalid use of property, "Me.filter" I
thought refered to the souce of my form,

I've gone to Help and that tells me that I'm trying to
write to a read-Only property.
 
Your cancatonation does seem to have been accepted now
the the compiler ginine me another error message, it
tells me that:

Me.Filter is an invalid use of property, "Me.filter" I
thought refered to the souce of my form,

I've gone to Help and that tells me that I'm trying to
write to a read-Only property.
-----Original Message-----
-----Original Message-----
Concatenate the value from the text box into the string:
Strfilter = "[Customer_Name] Like ""*" & [Me.searchName] & "*"""

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Hi

I have a form that displays the relevant info about the
Customers, it is based on a query (QryCustomers).

I want my users to be able to filter the form based on
characters typed into a Textbox for instance:

if the user types: "Carl" in the Textbox I would like to
filter all the records with "Carl" anywhere in the
Customer_Name field to be displayed

When I use the formula:

Like "*[Carl]*"

in the Criteria column of the query it returns the
required records, but when I try to reproduce this in a
VBA module. i.e.

Dim Strfilter as string

Strfilter = "[Customer_Name] Like *[Me.searchName]*"
Me.filter "Strfilter"

I have tried various alternatives using the Ampersand &
and the Sigle quote ' , but each time I seem to get an
error(usaully a syntax error)

can anyone help?
thanks


Ps: I have also tried to create a Recordset but I run
into the same problem the compiler doesn't seem to want
to recognise the wildcard * character. In any case i'm
still trying to figure out how to asign the new recordset
to an opoen form?
.
 
Try:
Me.Filter = Strfilter
Me.FilterOn = True

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

johnG said:
Your cancatonation does seem to have been accepted now
the the compiler ginine me another error message, it
tells me that:

Me.Filter is an invalid use of property, "Me.filter" I
thought refered to the souce of my form,

I've gone to Help and that tells me that I'm trying to
write to a read-Only property.
-----Original Message-----
-----Original Message-----
Concatenate the value from the text box into the string:
Strfilter = "[Customer_Name] Like ""*" & [Me.searchName] & "*"""


Hi

I have a form that displays the relevant info about the
Customers, it is based on a query (QryCustomers).

I want my users to be able to filter the form based on
characters typed into a Textbox for instance:

if the user types: "Carl" in the Textbox I would like to
filter all the records with "Carl" anywhere in the
Customer_Name field to be displayed

When I use the formula:

Like "*[Carl]*"

in the Criteria column of the query it returns the
required records, but when I try to reproduce this in a
VBA module. i.e.

Dim Strfilter as string

Strfilter = "[Customer_Name] Like *[Me.searchName]*"
Me.filter "Strfilter"

I have tried various alternatives using the Ampersand &
and the Sigle quote ' , but each time I seem to get an
error(usaully a syntax error)

can anyone help?
thanks


Ps: I have also tried to create a Recordset but I run
into the same problem the compiler doesn't seem to want
to recognise the wildcard * character. In any case i'm
still trying to figure out how to asign the new recordset
to an opoen form?
 
Back
Top