Filtering records on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a form on which I have a combo box which filters a User Name field
combo box on the form, depending on which User Name I select. The code I'm
using is
DoCmd.ApplyFilter , "[LoggedByID] = " & str(Me![cmbFilterMgr]) on the After
Update event and this works.

However, on a second form which is a read only form and shows the same
records as the first form, except with less detail, I have the same combo box
with the same code, only this time it's filtering a User Name field that is
not a combo box. Here the code does not work. I can't figure out why? Any
suggestions? Thanks in advance.

Janet
 
Assuming that your User Name field is text you need to include quotes around it:

DoCmd.ApplyFilter , "UserName = '" & FilterUserName & "'"

Change the names as appropriate!

HTH
John
 
Hi John,

My User Name field is text, but the code you gave me just does what
everything else I've tried has done. When I select a User name in my filter
combo my whole form goes blank. I can only see my headers. My form is a
continuous form, I don't if that makes any difference or not.

thanks,
Janet

John Smith said:
Assuming that your User Name field is text you need to include quotes around it:

DoCmd.ApplyFilter , "UserName = '" & FilterUserName & "'"

Change the names as appropriate!

HTH
John
I have a form on which I have a combo box which filters a User Name field
combo box on the form, depending on which User Name I select. The code I'm
using is
DoCmd.ApplyFilter , "[LoggedByID] = " & str(Me![cmbFilterMgr]) on the After
Update event and this works.
However, on a second form which is a read only form and shows the same
records as the first form, except with less detail, I have the same combo box
with the same code, only this time it's filtering a User Name field that is
not a combo box. Here the code does not work. I can't figure out why? Any
suggestions? Thanks in advance.
 
I must admit that I don't use the ApplyFilter method myself, I would use:

Me.Filter = "UserName = '" & FilterUserName & "'"
Me.FilterOn = True

It might be worth trying that. Also, I assume that you have checked that the
name you are searching for is actually in the table, all too easy when testing
to miss the obvious; been there! Additionally, is your back-end case
sensitive? If it is a DBMS rather than Access it may be, in which case try:

"UCase$(UserName) = '" & UCase$(FilterUserName) & "'"

John
My User Name field is text, but the code you gave me just does what
everything else I've tried has done. When I select a User name in my filter
combo my whole form goes blank. I can only see my headers. My form is a
continuous form, I don't if that makes any difference or not.

John Smith said:
Assuming that your User Name field is text you need to include quotes around it:
DoCmd.ApplyFilter , "UserName = '" & FilterUserName & "'"
Change the names as appropriate!
I have a form on which I have a combo box which filters a User Name field
combo box on the form, depending on which User Name I select. The code I'm
using is
DoCmd.ApplyFilter , "[LoggedByID] = " & str(Me![cmbFilterMgr]) on the After
Update event and this works.
However, on a second form which is a read only form and shows the same
records as the first form, except with less detail, I have the same combo box
with the same code, only this time it's filtering a User Name field that is
not a combo box. Here the code does not work. I can't figure out why? Any
suggestions? Thanks in advance.
 
Hi John,

Strangely enough those didn't work either. I still get a blank form when I
choose a user name. To explain the form a little more clearly, it is based
on a query, and the User field is actually taken from a lookup table in the
query. In my main table I have a field called LoggedByID and in my query I
have joined it to the User ID of the User table, and then put the User field
from the User table into my query. It is not case sensitive. Any other
ideas? I appreciate your help.

thanks,
Janet

John Smith said:
I must admit that I don't use the ApplyFilter method myself, I would use:

Me.Filter = "UserName = '" & FilterUserName & "'"
Me.FilterOn = True

It might be worth trying that. Also, I assume that you have checked that the
name you are searching for is actually in the table, all too easy when testing
to miss the obvious; been there! Additionally, is your back-end case
sensitive? If it is a DBMS rather than Access it may be, in which case try:

"UCase$(UserName) = '" & UCase$(FilterUserName) & "'"

John
My User Name field is text, but the code you gave me just does what
everything else I've tried has done. When I select a User name in my filter
combo my whole form goes blank. I can only see my headers. My form is a
continuous form, I don't if that makes any difference or not.

John Smith said:
Assuming that your User Name field is text you need to include quotes around it:
DoCmd.ApplyFilter , "UserName = '" & FilterUserName & "'"
Change the names as appropriate!

JanetF wrote:
I have a form on which I have a combo box which filters a User Name field
combo box on the form, depending on which User Name I select. The code I'm
using is
DoCmd.ApplyFilter , "[LoggedByID] = " & str(Me![cmbFilterMgr]) on the After
Update event and this works.
However, on a second form which is a read only form and shows the same
records as the first form, except with less detail, I have the same combo box
with the same code, only this time it's filtering a User Name field that is
not a combo box. Here the code does not work. I can't figure out why? Any
suggestions? Thanks in advance.
 
Back
Top