Solved

How to close Filter by Form view using code

Posted on 2007-11-26
5
436 Views
Last Modified: 2008-02-01
When you click on the Filter by Form toolbar button, the active form changes to filter-by-form view. If you then click 'Close' on the Filter/Sort toolbar, the form reverts to normal view.
What is the code equivalent of clicking 'Close' on the Filter/Sort toolbar?
I've tried
   DoCmd.RunCommand acCmdClose
but I get
   Error: No current record.
0
Comment
Question by:Milewskp
5 Comments
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 20354839
try this:
DoCmd.RunCommand acCmdCloseWindow
0
 
LVL 3

Expert Comment

by:incrediblejohn
ID: 20355623

DoCmd.RunCommand acCmdRemoveFilterSort
0
 
LVL 1

Accepted Solution

by:
Milewskp earned 0 total points
ID: 20451117
DoCmd.RunCommand acCmdCloseWindow results in a "No Current record" error.

DoCmd.RunCommand acCmdRemoveFilterSort results in a "The action RemoveFilterSort is not available now" error.

I found that this works:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Dim Answer As String
    Const conCantFilterByFormWhenRecordSourceIsARecordsetError As Integer = 2594 'AccessError constant
    
    If DataErr = conCantFilterByFormWhenRecordSourceIsARecordsetError Then
        'Can't FilterByForm when Me.Recordsource is a Recordset
        Answer = MsgBox("Filter by Form is not allowed for this form." & vbCr & _
        "(Recordsource of the form or subform is a Recordset.)", vbOKCancel + vbExclamation)
        Response = acDataErrContinue 'Prevent Access from displaying its own message.
        DoCmd.Close 'Close FilterByForm view
        DoCmd.OpenForm Me.Parent.Name 'Reopen form.
 
    End If
    
End Sub

Open in new window

0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20535819
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question