Automating datasheet/form view switch in subforms?

J

Jon Furman

This is kind of an oldie but goody that I never figured out a real answer
to. Here's the situation...I have a form containing a series of nested
subforms. So form A contains subform B which itself contains subform C and C
also contains subform D. Now through the form interface I can place my mouse
pointer over any one of these subforms and select the datasheet view option
under the subform menu the pops up on a right click. So with a total of 4
clicks I can switch each nested subform to a datasheet and then back to form
view again. What I would like to do is place a single button on form A that
would automatically toggle the datasheet view on/off on subforms B,C & D
simultaneously and do so through a VBA procedure. Now I have found a way to
do this but it isn't very elegant. It seems that I must make sure that the
form object in each subform I want to switch has the focus by one it's
editable controls being selected. Only then I can run a
DoCmd.RunCommand(Command:=acCmdSubformDatasheetView) to swap to datasheet
view (& use the acCmdSubformFormView argument to return back to form view).
Then I must set the focus to the next nested subform and do the same thing.
There are two big problems with this, the first is that I must first loop
through the subform's controls to find the first editable control and set
the focus before the command to switch views is available and the other is
that the whole technique fails if the subform I've navigated down to happens
to have no records for the current parent record. I would be grateful to
anyone who can shed some light on a better way to solve this one. Thanks for
reading!


Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top