Solved

toggle subform List/Datasheet via VBA

Posted on 2006-07-10
6
1,013 Views
Last Modified: 2008-09-15
I want to place a toogle-button on the mainform to toggle the subform views.
How can I advise the form to switch the view via VBA?
Chris
0
Comment
Question by:chriswies
6 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17071597
You can try this

Me.mysubform.form.CurrentView = myviewno

where mysubform = name of your subform
and myviewno is a number to identify what view u want

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17071605
DesignView is view number 0
Form View is 1
Datashee view is 2

ok, it seems CurrentView is a readonly property, so Im thinking u have to open form in Design mode, then change view, then reopen

0
 
LVL 54

Expert Comment

by:nico5038
ID: 17071712
A non-code solution would be to use a tab control with a subform per page and let the tabs work as "toggle button"

Nic;o)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 17072188
chriswies

try this

say you had a button on your mainform called cmdToggleView

private sub cmdToggleView_Click

    Me.mysubform.SetFocus
    If Me.mysubform.Form.CurrentView = 1 Then DoCmd.RunCommand acCmdSubformDatasheetView Else DoCmd.RunCommand acCmdSubformFormView

end sub


set focus to subform called  mysubform
if current view is form view then change to datasheet else change to form
0
 
LVL 39

Expert Comment

by:stevbe
ID: 17077116
If I remember correctly you don't need to do the test the CurrentView as setting to acCmdSubformDatasheetView will actually toggle between the 2 view types for you.
0
 
LVL 2

Expert Comment

by:Chi Is Current
ID: 21250748
Sweet solution!  Thanks!!!  Jacob
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

13 Experts available now in Live!

Get 1:1 Help Now