Solved

How to close Filter by Form view using code

Posted on 2007-11-26
5
427 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now