Re: Change DefaultView using VBA

  • Thread starter George Nicholson
  • Start date
G

George Nicholson

This won't change DefaultView (I'm not sure you can), but you can change the
view at runtime (if ViewsAllowed is set to Both)

if ctlSubform.Form.CurrentView = 1 Then form is currently in FormView
(read-only)
if ctlSubform.Form.CurrentView = 2 Then form is currently in Datasheet View

to toggle to the "other" view:

ctlSubform.SetFocus
DoCmd.RunCommand acCmdSubformDatasheet

There may be a more elegant way to do this but this is the only way I found
that is compatible with Access 97 thru 2002(XP).

HTH,
George Nicholson

Remove 'Junk' from return address.


Stephen Powers said:
I would like to allow my users to change the default view of a form
(actually a subform). I am unable to change the Defaultview property except
in design view. Any suggestions on how to do this using VBA?
 
G

Guest

Thanks. I have similar code already to change the current view. What I need to do is allow the users to "configure" the default view rather than always have to change views manually. If I set up a table to store the defaultview property setting could I somehow reference it when I load the subform? This would not change the defaultView but would accomplish the same thing. Other ideas?
 
G

George Nicholson

AFAIK, you'd need to do what you suggest: but store the "user's" view
setting (not DefaultView, which won't be changing) and then set the view
based on that when on opening the form (and saving the value when the user
changes it).

OR: (programatically) you could open the form in design view, reset the
DefaultView value and then save the form. I've never tried it, but it
should be possible, I'm sure (except maybe in a Runtime application). For
instance: when the form closes, check to see if the view setting has changed
since it was opened and finish closing the form. If the view setting
changed: turn echo off, reopen form in design view, change the DefaultView
setting, close & save the form, turn echo on. Or something like that...
:) This way DefaultView would be storing the "last-used" View setting and
the form would reflect that when next opened. No need for a separate table.

Good luck,

George Nicholson

Remove 'Junk' from return address.


Stephen Powers said:
Thanks. I have similar code already to change the current view. What I
need to do is allow the users to "configure" the default view rather than
always have to change views manually. If I set up a table to store the
defaultview property setting could I somehow reference it when I load the
subform? This would not change the defaultView but would accomplish the
same thing. Other ideas?
 

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

Top