Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to remove filter when closing form? 1

Status
Not open for further replies.

jonmitch

IS-IT--Management
Oct 15, 2002
21
US
I have a switchboard that links to a "Master Form". From the swichboard you can open the form in Add Mode and open the form in Edit Mode. I also have a textbox with a command button next to it that acts as a search for CompanyName to the Master Form.
Here's my dilemma:
When I type in a CompanyName to search, it brings me to the Master Form filtered for that matching record (I like this). Now when I close the form and go back to switchboard and this time click Edit Companies, I am brought to the Master Form with the filter still in place. Only when I close the switchboard is the filter to the Master Form removed.
How can I get it so the filter is removed everytime I close the Master Form?

Thanks all!
 
In the close event for the form use
[tt]Me.FilterOn = False[/tt]

 
One additional item I was looking to do:
The search is set up right now so that it looks for a string of letter in the whole company name. Can it be set up so that it starts at the beginning of the company name? For example, if I type in the letters “ce” in the search, the company Advanced pops up because Advanced has “ce” in it. I only want it to show companies that start with “Ce”. Is that possible?
Here is the pertinent code on the Switchboard now:

Private Sub cmdFind_Click()
sgFilter = Trim("" & Me![txtFind])
blngFilter = True
DoCmd.OpenForm "Master Form"
End Sub

Private Sub Form_Load()
DoCmd.Maximize
DoCmd.RunMacro "Hide Form View"
blngFilter = False
sgFilter = ""
End Sub

Here is the pertinent code on the Master Form:
Private Sub Form_Open(Cancel As Integer)
Dim strFilter As String
If blngFilter = True Then
strFilter = "CompanyName LIKE '*" & sgFilter & "*'"
Me.Filter = strFilter
Me.FilterOn = True
Me.Requery
End If
End Sub
 
Change the code like this

Private Sub Form_Open(Cancel As Integer)
Dim strFilter As String
If blngFilter = True Then
strFilter = "CompanyName LIKE '" & sgFilter & "*'"
Me.Filter = strFilter
Me.FilterOn = True
Me.Requery
End If
End Sub
Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
Thanks for the reply back, but that did not do it, plus I am still having the problem that the filter will not go away when I go back to the switchboard.

Any more ideas? I'll try anything!
 
In Form_Unload event or close event
Me.FilterOn = False
Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
Thanks essnrv, but here's how I fixed the problem, in case others are wondering. I created a Macro that closed the Switchboard. I put that Macro in the Submit button so that when you type in data to search, it opens the main form filtered and also closes the Switchboard. So when I go back to the switchboard, it is reloaded and it works fine!

I still however am puzzled about the search function. Is there a way to tweak the code so that it starts at the beginning of the name?

Thanks for all the great help!
 
Actually it did work!!!!!!!!!!!

Thanks so much essnrv for all your expert help over the last two days!!!! I greatlt appreciate it!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top