working with filters

A

Afrosheen

I hope this gets through. I've posted before and could not find any of the
posts. I'll try again.

I have 4 buttons in form1. Each button opens a form with a filter.

Dim stDocName As String
Dim stwhere As String
Dim stLinkCriteria As String
stwhere = "[shift]='a-days' or [shift]='day shift'"
stDocName = "Frm_roster"
DoCmd.OpenForm stDocName, , , stwhere


In form2, it creates the filter ok. The problem is that I need a button
{toggle or command} to turn the filter off then back on. This is what I have
behind the toggle button I've created.

Static flg As Boolean
If flg Then
Me.Form.FilterOn = True
flg = False
Else
Me.Form.FilterOn = False
Me.Form.Filter = ""
flg = True
End If

I can't get this to work. I've been working on this for 3 days now.

If I can get the filtered statment in form 2 to transfer to a string, then
it might work. I don't know.

I'm starting to pull what hair I have left out.
Thanks
 
R

Rui

I can only see one problem with your code.

you are declaring a static fld in your code and it may be affecting the
functional work of the form.

I would suggest that you create a new module and insert the following:
Global fld as boolean '(save and close this module)
then create an event on form_open for the form you want filtering and add
fld = True
then in the toggle button use
If flg Then
Me.Form.FilterOn = False
flg = False
Else
Me.Form.Filter = "[shift]='a-days' or [shift]='day shift'"
Me.Form.FilterOn = True
flg = True
End If

Hope it helps
Rui
 
A

Afrosheen

Hi Rui,
I created a module called module 2 and put "global fld as boolean" {no
quotes} and saved it.
I did an event on open fld = true

The only thing I didn't enter was: Me.Form.Filter = "[shift]='a-days' or
[shift]='day shift'" because this changes with each click of a command button
on form 1. For example: the 4 buttons are "A-Days", "B-Days". The other two
are A and B Nights. The stwhere string is: "[shift]='b-days' or [shift] =
'day shift'". The other two would [shift] =' b-nights' or [shift]='night
shift'".

I tried using:me.filter = stwhere but that didn't work.

I hope that kind of explains it better.

Rui said:
I can only see one problem with your code.

you are declaring a static fld in your code and it may be affecting the
functional work of the form.

I would suggest that you create a new module and insert the following:
Global fld as boolean '(save and close this module)
then create an event on form_open for the form you want filtering and add
fld = True
then in the toggle button use
If flg Then
Me.Form.FilterOn = False
flg = False
Else
Me.Form.Filter = "[shift]='a-days' or [shift]='day shift'"
Me.Form.FilterOn = True
flg = True
End If

Hope it helps
Rui

Afrosheen said:
I hope this gets through. I've posted before and could not find any of the
posts. I'll try again.

I have 4 buttons in form1. Each button opens a form with a filter.

Dim stDocName As String
Dim stwhere As String
Dim stLinkCriteria As String
stwhere = "[shift]='a-days' or [shift]='day shift'"
stDocName = "Frm_roster"
DoCmd.OpenForm stDocName, , , stwhere


In form2, it creates the filter ok. The problem is that I need a button
{toggle or command} to turn the filter off then back on. This is what I have
behind the toggle button I've created.

Static flg As Boolean
If flg Then
Me.Form.FilterOn = True
flg = False
Else
Me.Form.FilterOn = False
Me.Form.Filter = ""
flg = True
End If

I can't get this to work. I've been working on this for 3 days now.

If I can get the filtered statment in form 2 to transfer to a string, then
it might work. I don't know.

I'm starting to pull what hair I have left out.
Thanks
 
R

Rui

I tested the solution with some generic values and it worked for me so I
guess the bit missing in your code to make it work is actually the filter
criteria.

A possible solution is to reference the filter like:

[field_name] = me![control_name]

where [control_name] is the text box or other control that you base the
filter on.



Rui
Afrosheen said:
Hi Rui,
I created a module called module 2 and put "global fld as boolean" {no
quotes} and saved it.
I did an event on open fld = true

The only thing I didn't enter was: Me.Form.Filter = "[shift]='a-days' or
[shift]='day shift'" because this changes with each click of a command button
on form 1. For example: the 4 buttons are "A-Days", "B-Days". The other two
are A and B Nights. The stwhere string is: "[shift]='b-days' or [shift] =
'day shift'". The other two would [shift] =' b-nights' or [shift]='night
shift'".

I tried using:me.filter = stwhere but that didn't work.

I hope that kind of explains it better.

Rui said:
I can only see one problem with your code.

you are declaring a static fld in your code and it may be affecting the
functional work of the form.

I would suggest that you create a new module and insert the following:
Global fld as boolean '(save and close this module)
then create an event on form_open for the form you want filtering and add
fld = True
then in the toggle button use
If flg Then
Me.Form.FilterOn = False
flg = False
Else
Me.Form.Filter = "[shift]='a-days' or [shift]='day shift'"
Me.Form.FilterOn = True
flg = True
End If

Hope it helps
Rui

Afrosheen said:
I hope this gets through. I've posted before and could not find any of the
posts. I'll try again.

I have 4 buttons in form1. Each button opens a form with a filter.

Dim stDocName As String
Dim stwhere As String
Dim stLinkCriteria As String
stwhere = "[shift]='a-days' or [shift]='day shift'"
stDocName = "Frm_roster"
DoCmd.OpenForm stDocName, , , stwhere


In form2, it creates the filter ok. The problem is that I need a button
{toggle or command} to turn the filter off then back on. This is what I have
behind the toggle button I've created.

Static flg As Boolean
If flg Then
Me.Form.FilterOn = True
flg = False
Else
Me.Form.FilterOn = False
Me.Form.Filter = ""
flg = True
End If

I can't get this to work. I've been working on this for 3 days now.

If I can get the filtered statment in form 2 to transfer to a string, then
it might work. I don't know.

I'm starting to pull what hair I have left out.
Thanks
 
A

Afrosheen

Ok, First of all, I'm sorry if I act dumb. I've only been at Access for a
bout a month.

The thing is that the filter is put in the form filter field on the docmd.

The control field would be on the form it's self.
stwhere = me.[filter]

Can I use the above string?

[shift] = me.[filter] The shift field is the filtered field. Sorry, where
would it go?

sorry and thanks

Rui said:
I tested the solution with some generic values and it worked for me so I
guess the bit missing in your code to make it work is actually the filter
criteria.

A possible solution is to reference the filter like:

[field_name] = me![control_name]

where [control_name] is the text box or other control that you base the
filter on.



Rui
Afrosheen said:
Hi Rui,
I created a module called module 2 and put "global fld as boolean" {no
quotes} and saved it.
I did an event on open fld = true

The only thing I didn't enter was: Me.Form.Filter = "[shift]='a-days' or
[shift]='day shift'" because this changes with each click of a command button
on form 1. For example: the 4 buttons are "A-Days", "B-Days". The other two
are A and B Nights. The stwhere string is: "[shift]='b-days' or [shift] =
'day shift'". The other two would [shift] =' b-nights' or [shift]='night
shift'".

I tried using:me.filter = stwhere but that didn't work.

I hope that kind of explains it better.

Rui said:
I can only see one problem with your code.

you are declaring a static fld in your code and it may be affecting the
functional work of the form.

I would suggest that you create a new module and insert the following:
Global fld as boolean '(save and close this module)
then create an event on form_open for the form you want filtering and add
fld = True
then in the toggle button use
If flg Then
Me.Form.FilterOn = False
flg = False
Else
Me.Form.Filter = "[shift]='a-days' or [shift]='day shift'"
Me.Form.FilterOn = True
flg = True
End If

Hope it helps
Rui

:

I hope this gets through. I've posted before and could not find any of the
posts. I'll try again.

I have 4 buttons in form1. Each button opens a form with a filter.

Dim stDocName As String
Dim stwhere As String
Dim stLinkCriteria As String
stwhere = "[shift]='a-days' or [shift]='day shift'"
stDocName = "Frm_roster"
DoCmd.OpenForm stDocName, , , stwhere


In form2, it creates the filter ok. The problem is that I need a button
{toggle or command} to turn the filter off then back on. This is what I have
behind the toggle button I've created.

Static flg As Boolean
If flg Then
Me.Form.FilterOn = True
flg = False
Else
Me.Form.FilterOn = False
Me.Form.Filter = ""
flg = True
End If

I can't get this to work. I've been working on this for 3 days now.

If I can get the filtered statment in form 2 to transfer to a string, then
it might work. I don't know.

I'm starting to pull what hair I have left out.
Thanks
 
R

Rui

No. If you are using a filter on the form, this assumes that you are not
restricting the data that goes into the form (i.e. the form's record source
is a table or a query).
By filtering, you are only saying - display me only the ones I want to see.

The process is similar to a where clause, but in a where clause you cannot
take the filter out to check all data.

Now, lets say you have a form that displays all the records in a given
month. And you want to filter it for a specific day. All you have to do is to
add a textbox or any other control, where you can type or choose the specific
date.

The filter is then applied to the form by doing something like (using the
example i gave you before):

If flg Then 'this will remove any existing
filter on the form
Me.Form.FilterOn = False
flg = False
Else 'this will apply a filter on the
form
Me.Form.Filter = "[date]=#" & me.[filter_textbox] & "#"
Me.Form.FilterOn = True 'make it active
flg = True
End If


Hope this helps,
Rui

Afrosheen said:
Ok, First of all, I'm sorry if I act dumb. I've only been at Access for a
bout a month.

The thing is that the filter is put in the form filter field on the docmd.

The control field would be on the form it's self.
stwhere = me.[filter]

Can I use the above string?

[shift] = me.[filter] The shift field is the filtered field. Sorry, where
would it go?

sorry and thanks

Rui said:
I tested the solution with some generic values and it worked for me so I
guess the bit missing in your code to make it work is actually the filter
criteria.

A possible solution is to reference the filter like:

[field_name] = me![control_name]

where [control_name] is the text box or other control that you base the
filter on.



Rui
Afrosheen said:
Hi Rui,
I created a module called module 2 and put "global fld as boolean" {no
quotes} and saved it.
I did an event on open fld = true

The only thing I didn't enter was: Me.Form.Filter = "[shift]='a-days' or
[shift]='day shift'" because this changes with each click of a command button
on form 1. For example: the 4 buttons are "A-Days", "B-Days". The other two
are A and B Nights. The stwhere string is: "[shift]='b-days' or [shift] =
'day shift'". The other two would [shift] =' b-nights' or [shift]='night
shift'".

I tried using:me.filter = stwhere but that didn't work.

I hope that kind of explains it better.

:

I can only see one problem with your code.

you are declaring a static fld in your code and it may be affecting the
functional work of the form.

I would suggest that you create a new module and insert the following:
Global fld as boolean '(save and close this module)
then create an event on form_open for the form you want filtering and add
fld = True
then in the toggle button use
If flg Then
Me.Form.FilterOn = False
flg = False
Else
Me.Form.Filter = "[shift]='a-days' or [shift]='day shift'"
Me.Form.FilterOn = True
flg = True
End If

Hope it helps
Rui

:

I hope this gets through. I've posted before and could not find any of the
posts. I'll try again.

I have 4 buttons in form1. Each button opens a form with a filter.

Dim stDocName As String
Dim stwhere As String
Dim stLinkCriteria As String
stwhere = "[shift]='a-days' or [shift]='day shift'"
stDocName = "Frm_roster"
DoCmd.OpenForm stDocName, , , stwhere


In form2, it creates the filter ok. The problem is that I need a button
{toggle or command} to turn the filter off then back on. This is what I have
behind the toggle button I've created.

Static flg As Boolean
If flg Then
Me.Form.FilterOn = True
flg = False
Else
Me.Form.FilterOn = False
Me.Form.Filter = ""
flg = True
End If

I can't get this to work. I've been working on this for 3 days now.

If I can get the filtered statment in form 2 to transfer to a string, then
it might work. I don't know.

I'm starting to pull what hair I have left out.
Thanks
 
A

Afrosheen

I believe it is working now. Thank you for you help. It has been much
appreciated

Thanks

Rui said:
No. If you are using a filter on the form, this assumes that you are not
restricting the data that goes into the form (i.e. the form's record source
is a table or a query).
By filtering, you are only saying - display me only the ones I want to see.

The process is similar to a where clause, but in a where clause you cannot
take the filter out to check all data.

Now, lets say you have a form that displays all the records in a given
month. And you want to filter it for a specific day. All you have to do is to
add a textbox or any other control, where you can type or choose the specific
date.

The filter is then applied to the form by doing something like (using the
example i gave you before):

If flg Then 'this will remove any existing
filter on the form
Me.Form.FilterOn = False
flg = False
Else 'this will apply a filter on the
form
Me.Form.Filter = "[date]=#" & me.[filter_textbox] & "#"
Me.Form.FilterOn = True 'make it active
flg = True
End If


Hope this helps,
Rui

Afrosheen said:
Ok, First of all, I'm sorry if I act dumb. I've only been at Access for a
bout a month.

The thing is that the filter is put in the form filter field on the docmd.

The control field would be on the form it's self.
stwhere = me.[filter]

Can I use the above string?

[shift] = me.[filter] The shift field is the filtered field. Sorry, where
would it go?

sorry and thanks

Rui said:
I tested the solution with some generic values and it worked for me so I
guess the bit missing in your code to make it work is actually the filter
criteria.

A possible solution is to reference the filter like:

[field_name] = me![control_name]

where [control_name] is the text box or other control that you base the
filter on.



Rui
:

Hi Rui,
I created a module called module 2 and put "global fld as boolean" {no
quotes} and saved it.
I did an event on open fld = true

The only thing I didn't enter was: Me.Form.Filter = "[shift]='a-days' or
[shift]='day shift'" because this changes with each click of a command button
on form 1. For example: the 4 buttons are "A-Days", "B-Days". The other two
are A and B Nights. The stwhere string is: "[shift]='b-days' or [shift] =
'day shift'". The other two would [shift] =' b-nights' or [shift]='night
shift'".

I tried using:me.filter = stwhere but that didn't work.

I hope that kind of explains it better.

:

I can only see one problem with your code.

you are declaring a static fld in your code and it may be affecting the
functional work of the form.

I would suggest that you create a new module and insert the following:
Global fld as boolean '(save and close this module)
then create an event on form_open for the form you want filtering and add
fld = True
then in the toggle button use
If flg Then
Me.Form.FilterOn = False
flg = False
Else
Me.Form.Filter = "[shift]='a-days' or [shift]='day shift'"
Me.Form.FilterOn = True
flg = True
End If

Hope it helps
Rui

:

I hope this gets through. I've posted before and could not find any of the
posts. I'll try again.

I have 4 buttons in form1. Each button opens a form with a filter.

Dim stDocName As String
Dim stwhere As String
Dim stLinkCriteria As String
stwhere = "[shift]='a-days' or [shift]='day shift'"
stDocName = "Frm_roster"
DoCmd.OpenForm stDocName, , , stwhere


In form2, it creates the filter ok. The problem is that I need a button
{toggle or command} to turn the filter off then back on. This is what I have
behind the toggle button I've created.

Static flg As Boolean
If flg Then
Me.Form.FilterOn = True
flg = False
Else
Me.Form.FilterOn = False
Me.Form.Filter = ""
flg = True
End If

I can't get this to work. I've been working on this for 3 days now.

If I can get the filtered statment in form 2 to transfer to a string, then
it might work. I don't know.

I'm starting to pull what hair I have left out.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top