toggle subform List/Datasheet via VBA

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
chriswiesAsked:
Who is Participating?
 
rockiroadsConnect With a Mentor Commented:
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
 
rockiroadsCommented:
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
 
rockiroadsCommented:
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
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
nico5038Commented:
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
 
stevbeCommented:
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
 
Chi Is CurrentCommented:
Sweet solution!  Thanks!!!  Jacob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.