Automatically removing filter from form

T

TotallyConfused

I posted this on General questions. Please accept my apologies - but this is
a Form question.

How do I remove a filter from a form automatically? I have a doc form that
lists pts assoc with doc. Upon double clicking on specific pt. I have this
code that take me to the PT FORM for this specific pt. This works fine.
However, after reviewing pt on PT FORM I want to remove filter automatically.
I tried a requery but that does not work. Can you please help. Thank in
advance.

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub
 
D

Douglas J. Steele

Actually, that's not a filter you're using: you're actually impacting the
recordsource of the form, so that it only has those records.

To do what you want, you could pass "[PTID]='" & Me![PTID] & "'" as the
OpenArgs parameter, then set the filter in the form's Load event:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"

Then, in the module for PTFORM, you'd have something like:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If

End Sub

You could then add a button to remove the filter:

Private Sub cmdRemoveFilter_Click()

Me.Filter = vbNullString
Me.FilterOn = False

End Sub
 
T

TotallyConfused

Thank you for responding and I apologize for not clearly understanding. Do I
substitute the following:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"
in my existing code on the DOC FORM?

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub

If yes, I did and now when I click on the specific pt on the Doc form it
opens the PT Form but not to the specific pt. Am I missing something. I
followed your instructions. Can you please help. Thank you.

Douglas J. Steele said:
Actually, that's not a filter you're using: you're actually impacting the
recordsource of the form, so that it only has those records.

To do what you want, you could pass "[PTID]='" & Me![PTID] & "'" as the
OpenArgs parameter, then set the filter in the form's Load event:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"

Then, in the module for PTFORM, you'd have something like:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If

End Sub

You could then add a button to remove the filter:

Private Sub cmdRemoveFilter_Click()

Me.Filter = vbNullString
Me.FilterOn = False

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


TotallyConfused said:
I posted this on General questions. Please accept my apologies - but this
is
a Form question.

How do I remove a filter from a form automatically? I have a doc form
that
lists pts assoc with doc. Upon double clicking on specific pt. I have
this
code that take me to the PT FORM for this specific pt. This works fine.
However, after reviewing pt on PT FORM I want to remove filter
automatically.
I tried a requery but that does not work. Can you please help. Thank in
advance.

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub
 
D

Douglas J. Steele

Did you also make the change I said you needed to the Load event in form
PTFORM?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


TotallyConfused said:
Thank you for responding and I apologize for not clearly understanding.
Do I
substitute the following:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"
in my existing code on the DOC FORM?

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub

If yes, I did and now when I click on the specific pt on the Doc form it
opens the PT Form but not to the specific pt. Am I missing something. I
followed your instructions. Can you please help. Thank you.

Douglas J. Steele said:
Actually, that's not a filter you're using: you're actually impacting the
recordsource of the form, so that it only has those records.

To do what you want, you could pass "[PTID]='" & Me![PTID] & "'" as the
OpenArgs parameter, then set the filter in the form's Load event:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"

Then, in the module for PTFORM, you'd have something like:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If

End Sub

You could then add a button to remove the filter:

Private Sub cmdRemoveFilter_Click()

Me.Filter = vbNullString
Me.FilterOn = False

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


TotallyConfused said:
I posted this on General questions. Please accept my apologies - but
this
is
a Form question.

How do I remove a filter from a form automatically? I have a doc form
that
lists pts assoc with doc. Upon double clicking on specific pt. I have
this
code that take me to the PT FORM for this specific pt. This works
fine.
However, after reviewing pt on PT FORM I want to remove filter
automatically.
I tried a requery but that does not work. Can you please help. Thank
in
advance.

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub
 
T

TotallyConfused

Sorry - I had a couple of typos - It works great! However, once I am in the
PT Form it will not reset the form until I close the PT FORM. I have a
button that toggles to the DOC FORM. If I click on the Doc form button, it
will take me to the DOC FORM but if I dbl click on another PT it will take me
to the PT FORM but with the previous pt. even if I hit the remove filter
button. When I hit the remove filter button, it takes the form to the first
pt. The only way is to be able to choose another pt from the DOC FORM is to
close the PT FORM. How do I incorporate this step into the DOC FORM BUTTON
Did you also make the change I said you needed to the Load event in form
PTFORM?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


TotallyConfused said:
Thank you for responding and I apologize for not clearly understanding.
Do I
substitute the following:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"
in my existing code on the DOC FORM?

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub

If yes, I did and now when I click on the specific pt on the Doc form it
opens the PT Form but not to the specific pt. Am I missing something. I
followed your instructions. Can you please help. Thank you.

Douglas J. Steele said:
Actually, that's not a filter you're using: you're actually impacting the
recordsource of the form, so that it only has those records.

To do what you want, you could pass "[PTID]='" & Me![PTID] & "'" as the
OpenArgs parameter, then set the filter in the form's Load event:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"

Then, in the module for PTFORM, you'd have something like:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If

End Sub

You could then add a button to remove the filter:

Private Sub cmdRemoveFilter_Click()

Me.Filter = vbNullString
Me.FilterOn = False

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I posted this on General questions. Please accept my apologies - but
this
is
a Form question.

How do I remove a filter from a form automatically? I have a doc form
that
lists pts assoc with doc. Upon double clicking on specific pt. I have
this
code that take me to the PT FORM for this specific pt. This works
fine.
However, after reviewing pt on PT FORM I want to remove filter
automatically.
I tried a requery but that does not work. Can you please help. Thank
in
advance.

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub
 
D

Douglas J. Steele

Sorry, what's the DOC FORM BUTTON on the PT FORM?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


TotallyConfused said:
Sorry - I had a couple of typos - It works great! However, once I am in
the
PT Form it will not reset the form until I close the PT FORM. I have a
button that toggles to the DOC FORM. If I click on the Doc form button,
it
will take me to the DOC FORM but if I dbl click on another PT it will take
me
to the PT FORM but with the previous pt. even if I hit the remove filter
button. When I hit the remove filter button, it takes the form to the
first
pt. The only way is to be able to choose another pt from the DOC FORM is
to
close the PT FORM. How do I incorporate this step into the DOC FORM
BUTTON
Did you also make the change I said you needed to the Load event in form
PTFORM?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


TotallyConfused said:
Thank you for responding and I apologize for not clearly understanding.
Do I
substitute the following:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"
in my existing code on the DOC FORM?

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub

If yes, I did and now when I click on the specific pt on the Doc form
it
opens the PT Form but not to the specific pt. Am I missing something.
I
followed your instructions. Can you please help. Thank you.

:

Actually, that's not a filter you're using: you're actually impacting
the
recordsource of the form, so that it only has those records.

To do what you want, you could pass "[PTID]='" & Me![PTID] & "'" as
the
OpenArgs parameter, then set the filter in the form's Load event:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"

Then, in the module for PTFORM, you'd have something like:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If

End Sub

You could then add a button to remove the filter:

Private Sub cmdRemoveFilter_Click()

Me.Filter = vbNullString
Me.FilterOn = False

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I posted this on General questions. Please accept my apologies - but
this
is
a Form question.

How do I remove a filter from a form automatically? I have a doc
form
that
lists pts assoc with doc. Upon double clicking on specific pt. I
have
this
code that take me to the PT FORM for this specific pt. This works
fine.
However, after reviewing pt on PT FORM I want to remove filter
automatically.
I tried a requery but that does not work. Can you please help.
Thank
in
advance.

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub
 
T

TotallyConfused

The Doc Form Button on the PT Form is to toggle back and forth from Doc Form
to PT Form. I want to be able to when using the Doc Form button to
reset/clear the PT Form so that when I go back to the Doc form and choose a
pt. That pt will come up on my PT form. Don't want to have to close the form
in order to reset. Thank you very much for all your help. I really
appreciate it.

Douglas J. Steele said:
Sorry, what's the DOC FORM BUTTON on the PT FORM?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


TotallyConfused said:
Sorry - I had a couple of typos - It works great! However, once I am in
the
PT Form it will not reset the form until I close the PT FORM. I have a
button that toggles to the DOC FORM. If I click on the Doc form button,
it
will take me to the DOC FORM but if I dbl click on another PT it will take
me
to the PT FORM but with the previous pt. even if I hit the remove filter
button. When I hit the remove filter button, it takes the form to the
first
pt. The only way is to be able to choose another pt from the DOC FORM is
to
close the PT FORM. How do I incorporate this step into the DOC FORM
BUTTON
Did you also make the change I said you needed to the Load event in form
PTFORM?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message Thank you for responding and I apologize for not clearly understanding.
Do I
substitute the following:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"
in my existing code on the DOC FORM?

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub

If yes, I did and now when I click on the specific pt on the Doc form
it
opens the PT Form but not to the specific pt. Am I missing something.
I
followed your instructions. Can you please help. Thank you.

:

Actually, that's not a filter you're using: you're actually impacting
the
recordsource of the form, so that it only has those records.

To do what you want, you could pass "[PTID]='" & Me![PTID] & "'" as
the
OpenArgs parameter, then set the filter in the form's Load event:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"

Then, in the module for PTFORM, you'd have something like:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If

End Sub

You could then add a button to remove the filter:

Private Sub cmdRemoveFilter_Click()

Me.Filter = vbNullString
Me.FilterOn = False

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I posted this on General questions. Please accept my apologies - but
this
is
a Form question.

How do I remove a filter from a form automatically? I have a doc
form
that
lists pts assoc with doc. Upon double clicking on specific pt. I
have
this
code that take me to the PT FORM for this specific pt. This works
fine.
However, after reviewing pt on PT FORM I want to remove filter
automatically.
I tried a requery but that does not work. Can you please help.
Thank
in
advance.

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub
 
D

Douglas J. Steele

You'll need the code I gave you for cmdRemoveFilter_Click.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


TotallyConfused said:
The Doc Form Button on the PT Form is to toggle back and forth from Doc
Form
to PT Form. I want to be able to when using the Doc Form button to
reset/clear the PT Form so that when I go back to the Doc form and choose
a
pt. That pt will come up on my PT form. Don't want to have to close the
form
in order to reset. Thank you very much for all your help. I really
appreciate it.

Douglas J. Steele said:
Sorry, what's the DOC FORM BUTTON on the PT FORM?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


TotallyConfused said:
Sorry - I had a couple of typos - It works great! However, once I am
in
the
PT Form it will not reset the form until I close the PT FORM. I have a
button that toggles to the DOC FORM. If I click on the Doc form
button,
it
will take me to the DOC FORM but if I dbl click on another PT it will
take
me
to the PT FORM but with the previous pt. even if I hit the remove
filter
button. When I hit the remove filter button, it takes the form to the
first
pt. The only way is to be able to choose another pt from the DOC FORM
is
to
close the PT FORM. How do I incorporate this step into the DOC FORM
BUTTON
on the PT FORM?

Douglas J. Steele" wrote:

Did you also make the change I said you needed to the Load event in
form
PTFORM?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message Thank you for responding and I apologize for not clearly
understanding.
Do I
substitute the following:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"
in my existing code on the DOC FORM?

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub

If yes, I did and now when I click on the specific pt on the Doc
form
it
opens the PT Form but not to the specific pt. Am I missing
something.
I
followed your instructions. Can you please help. Thank you.

:

Actually, that's not a filter you're using: you're actually
impacting
the
recordsource of the form, so that it only has those records.

To do what you want, you could pass "[PTID]='" & Me![PTID] & "'" as
the
OpenArgs parameter, then set the filter in the form's Load event:

DoCmd.OpenForm "PTFORM, OpenArgs:="[PTID]='" & Me![PTID] & "'"

Then, in the module for PTFORM, you'd have something like:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If

End Sub

You could then add a button to remove the filter:

Private Sub cmdRemoveFilter_Click()

Me.Filter = vbNullString
Me.FilterOn = False

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


in
message I posted this on General questions. Please accept my apologies -
but
this
is
a Form question.

How do I remove a filter from a form automatically? I have a doc
form
that
lists pts assoc with doc. Upon double clicking on specific pt.
I
have
this
code that take me to the PT FORM for this specific pt. This
works
fine.
However, after reviewing pt on PT FORM I want to remove filter
automatically.
I tried a requery but that does not work. Can you please help.
Thank
in
advance.

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "PTFORM", , , "[PTID]='" & Me![PTID] & "'"

End Sub
 
R

Rick Brandt

Douglas said:
Actually, that's not a filter you're using: you're actually impacting
the recordsource of the form, so that it only has those records.

Are you saying that use of the WHERE argument of the OpenForm method is not
the same as applying a filter? That is all it does, apply a filter to the
form being opened. After opening all you have to do is use the "Remove
Filters" menu item and the form will show all records. Additionally you can
apply a totally different filter and it will be applied.

I have never thought of using the WHERE argument as anything besides a
standard filter.
 
D

Douglas J. Steele

Rick Brandt said:
Are you saying that use of the WHERE argument of the OpenForm method is
not the same as applying a filter? That is all it does, apply a filter to
the form being opened. After opening all you have to do is use the
"Remove Filters" menu item and the form will show all records.
Additionally you can apply a totally different filter and it will be
applied.

Really? While I obviously didn't test, I assumed opening a form with a Where
clause meant that only those records were available to the form, and that
was different than if you opened the form without a Where clause, and
limited what was displayed through a filter.
 
T

TotallyConfused

This is the code for the DOC form toggle button I have on my PT FORM. How do
I incorporate the Remove Filter? Where is the Remove filters menu? I
apologize for my ignorance but I am trying to learn VB. Thank you for your
help.

Private Sub Doc_Form_Click()
On Error GoTo Err_Doc_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm DOC"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_DOC_Form_Click:
Exit Sub

Err_DOC_Form_Click:
MsgBox Err.Description
Resume Exit_DOC_Form_Click

End Sub
 
D

Douglas J. Steele

Removing the filter from a form through VBA is:

Forms!NameOfForm.FilterOn = False

or, if you're using it on the same form,

Me.FilterOn = False

While you're removing the filter, you might also reset the filter to
nothing:

Forms!NameOfForm.Filter = vbNullString

or

Me.Filter = vbNullString

It's really not clear to me from which form you're trying to remove the
filter.
 
R

Rick Brandt

TotallyConfused said:
This is the code for the DOC form toggle button I have on my PT FORM. How do
I incorporate the Remove Filter? Where is the Remove filters menu? I
apologize for my ignorance but I am trying to learn VB. Thank you for your
help.

Why do you think you need to remove it? The filter is normally not saved unless
you go out of your way to do so. Closing the form should automatically discard
the filter that was applied.
 
T

TotallyConfused

Thank you all for your help. Removing filter from the Doc form. Reason I
need to remove filter is that the user needs to toggle back and forth between
Doc form and PT form. Do not want to be closing form after each lookup. It
is easier to toggle back and forth. Thank very much.
 
R

Rick Brandt

TotallyConfused said:
Thank you all for your help. Removing filter from the Doc form. Reason I
need to remove filter is that the user needs to toggle back and forth between
Doc form and PT form. Do not want to be closing form after each lookup. It
is easier to toggle back and forth. Thank very much.

You can just issue another OpenForm method with a different WHERE clause and
even if the form is already opened the new filter will be applied. There should
be no reason to remove the old one. The new filter will completely replace it.
 

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