Solved

ShowAllRecords in Access 2007 VBA does not work

Posted on 2010-09-14
6
952 Views
Last Modified: 2012-05-10
I am developing an app in Access 2007.

In a form, I have a subform that shows records from a table. I have a button that will filter this display reflecting a field in the displayed table that I have highlighted: code A. . Works a treat.
 I have another button that just does docmd.showallrecords (code B) - that does nothing apart from redisplaying according to the filetr I earlier specififed, it does not return to displaying the entire table. The Toggle filter button in the ribbon, however, does what it should and toggles between the latest filter and no filter.

This code works in Access 2002 (XP).

I repaired and compacted the app and that makes no difference...

Any ideas?
'code A

Private Sub Command9_Click()

'select similar sessions...



On Error GoTo Err_Command9_Click



    ' look at what was selected in the existing display

    Screen.PreviousControl.SetFocus

    ' fileter the table by this criterion

    DoCmd.RunCommand acCmdFilterBySelection



Exit_Command9_Click:

    Exit Sub



Err_Command9_Click:

    MsgBox err.description

    Resume Exit_Command9_Click

    

End Sub



'code B

Private Sub Command10_Click()

' show all sessions...



On Error GoTo Err_Command10_Click



    DoCmd.ShowAllRecords

    

Exit_Command10_Click:

    Exit Sub



Err_Command10_Click:

    MsgBox err.description

    Resume Exit_Command10_Click

    

End Sub

Open in new window

0
Comment
Question by:Peborgh
  • 3
  • 3
6 Comments
 
LVL 24

Expert Comment

by:Bitsqueezer
Comment Utility
Hi,

instead of "ShowAllRecords" simply set the Filter to an empty string:

Me.Filter=""
Me.FilterOn=False

Cheers,

Christian
0
 

Author Comment

by:Peborgh
Comment Utility
Sorry, as your defined it, nothing still hweppened.
I need an example of the syntax:
Say the form is "fred" and the subform "bill" lives in a control in fred calld jim, how do I set the filter for that inner form?

many thaks,

peter
0
 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 500 total points
Comment Utility
Hi Peter,

depends on where you want to execute the function. If you want to execute it in the subform then you can use the syntax above (in the click event of the button which should remove the filter).
If you have the button in the main form then you can use this instead:

Me.jim.Form.Filter=""
Me.jim.Form.FilterOn=False

The names of the main form and the sub form isn't important, you only need to know the name of the subform control (jim in your example).
A subform control can only have one form as child object so you get the reference to the child form with the "jim.Form" reference.

The "DoCmd" commands are in many cases only the functions which would be executed if you would have defined the same thing in a macro. And in many cases they work only if the form is activated where they should work on. So if you would use "Me.jim.Form.SetFocus" before the "DoCmd.ShowAllRecords" it should work, too. But in any case where you can avoid the "DoCmd" you should better use the methods and properties of the objects - in this case the "Filter" and "FilterOn" properties which any form object does have.

Cheers,

Christian
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Peborgh
Comment Utility
Christian, you're a very nice man! Your latest suggestion for a button in the main form worked!

And thanks for the dire warning re DoCmd...

Many thanks.

peter
0
 
LVL 24

Expert Comment

by:Bitsqueezer
Comment Utility
Hi Peter,

you're welcome.

Here's a little demo I wrote earlier to show you how to work with filters for a search form. With this you can filter any column of an endless form individually, very simple to implement:

http://www.office-loesung.de/ftopic13271_15_0_asc.php#

(You will find it at the end of the page, named "FilterDemo3.zip" to download.)

Cheers,

Christian
0
 

Author Comment

by:Peborgh
Comment Utility
Renewed thanks. Won't look at this immediately because of dealine pressures.

peter
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

743 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

17 Experts available now in Live!

Get 1:1 Help Now