Link to home
Start Free TrialLog in
Avatar of kbutler
kbutler

asked on

Is there a way to set default view (continuous form or single form) using VB?

I have a subform that is used in two different places. I would like to use VB code to set the default view to either continuous forms or single form, depending on which main form the user opens. Any ideas?

Thanks,
Kathleen
SOLUTION
Avatar of flavo
flavo
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kbutler
kbutler

ASKER

I don't need to switch from Datasheet view to Form View. I want the subform to open in either single form or continuous form depending on which main form they have selected. I tried the following:

  If GPFormUse = "Dev" Then
    Me.DefaultView = 1
  Else
    Me.DefaultView = 0
  End If

I get an error message that says "To set this property, open the form in design view".

I don't want to open in design view!

Thanks so much for your help on this!
Kathleen
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kbutler

ASKER

I will probably do that. I just spent several days reducing my duplicate forms and subforms (using vb to open with appropriate settings). I am trying to minimize duplication! I've tried opening the form in design view and setting the default value, then closing, but I still get the same error message.  I can't seem to come up with Visual Basic that allows me to open a form in continuous or single form mode. If anyone has any info on this, please pass on. I am going to close this one out. Thank you for trying!
Hi,

It is possible to do what you want, as long as the form is being called from another form, whether that be a mainline switching form, or another form.  I also, do not like multiple copies of forms.

The trick is,  to behind the scenes, programmatically open the form in design view, make the change, and close the form.  Then it will open as you like.

DoCmd.Echo False                             'Hide screen painting
DoCmd.OpenForm FormName:="YourFormName", View=acDesign  'Open In Design View
Forms![YourFormName].DefaultView = 0                ' 0=Single, 1=Continuous
DoCmd.RunCommand acCmdSave                          'Save the form with the new default property
DoCmd.Close ObjectType:=acForm, ObjectName:=[YourFormName}
DoCmd.Echo True                    'Turn back on screen painting

Note that you cannot use Me.DefaultView in the above

Also, I have experimented with DoCmd.RunCommand acCmdDesignView  and DoCmd.RunCommand acCmdForView to go from form view to design view, make the change, and then go back to Form view,  but I can't get this work in any of the opening events of the form using OpenArgs.  If I put the code in a Command Button on the form, then I can programmatically put it in design view, change, save, then change back to form view with good result.

Take Care,
Tom