Programmatically Switching Subform Views

  • Thread starter Thread starter Amar Kapadia
  • Start date Start date
A

Amar Kapadia

Hello Everyone:

Any information/assistance would be great. Thanks in advance.

I created a Main Form which includes a subform. By default, that subform is
shown as a datasheet view. Everything is fine and usuable, but I do notice
that users have a tough time entering into the field I have provided called
Notes when their notes are rather long. Unfortunately, for this reason and
that, the space for the subform is not very big. Anyway, Access XP does
provide a rather nice thing in that when I click on View...Subform...Form
View that datasheet turns into a Form View and now the Text Box for the
notes allows nice data entry for notes. Great. But I know my users and
getting them to click on Form...Subform...Datasheet view or Form view is
just too much for them. And with certain individuals having Office Adaptive
menus in place, often times this menu feature is hidden from them. So, I
wanted to create a toggle button right on the form to switch subform view
from Datasheet to Form. Just couldn't do it.

Does anyone know of the method, if it exist, to mimic this menu command so
that I can code it behind my toggle button? The menu command, again, is
View...Subform...Form View.

Also, having only Access XP right now, does anyone know if this ability to
switch subform views is an Access XP only feature or is it available in
Access 2000 as well.

Thank you
Amar
 
DoCmd.RunCommand acCmdSubformFormView

switches the Subform to FormView.


DoCmd.RunCommand acCmdSubformDatasheetView

switches the Subform to DatasheetView


DoCmd.RunCommand acCmdSubformDatasheet

toggles between 2 views.

Tested in A2K2 but AFAIK, they are available in A2K0.

HTH
Van T. Dinh
MVP (Access)
 
Hi Vin:

As always thank you for you prompt response to my question. I completely
understood the logic for your reply and was very excited to implement, but
got hung up somewhere. I've coded my ToggleSwitch:
 
Good Morning Van:

As always, thank you for you prompt reply to my question. I've followed
your suggestion, but unfortunately, came up to a bit of a snag. I'll paste
my code in a moment, but basically what is happening is that when I click on
my Toggle switch, I get a message from Access stating that that command
isn't available right now. Bummer...it all seemed very logical. Anyway,
I've confirmed the following:

1) I am in my subform before clicking on my toggle button.
2) I've made sure both the subform and the main form (just in case) both
allow Datasheet and Form Views.

Have I made a mistake in implementation? If any thing comes to mind, that
would be great...otherwise I'll just let it go. Here is the code Van.
Thanks in advance.

Amar

Private Sub tglSwitchView_AfterUpdate()

If tglSwitchView Then
DoCmd.RunCommand acCmdSubformFormView
Else
DoCmd.RunCommand acCmdSubformDatasheetView
End If

End Sub
 
Where is the ToggleButton located? On the Main Form or the Subform?

I tested them using the Immediate/Debug window. I *think* you may need to
but on the Main Form.
 
Back
Top