Solved

How to close Filter by Form view using code

Posted on 2007-11-26
5
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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