[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to close Filter by Form view using code

Posted on 2007-11-26
5
Medium Priority
?
452 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
4 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

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

834 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