Solved

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

Posted on 2004-04-04
6
765 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:kbutler
6 Comments
 
LVL 34

Assisted Solution

by:flavo
flavo earned 300 total points
ID: 10754136
yep!

From help file

Use Me.ViewsAllowed

You can use the DefaultView property to specify the opening view of a form.
·      You can use the ViewsAllowed property to specify whether users can switch between Datasheet view and Form view by clicking the Form View or Datasheet View command on the View menu or by clicking the arrow next to the View button and clicking Form View or Datasheet View.

Setting

The DefaultView property uses the following settings.

Setting      Description      Visual Basic
Single Form      (Default) Displays one record at a time.      0
Continuous Forms      Displays multiple records (as many as will fit in the current window), each in its own copy of the form's detail section.      1
Datasheet      Displays the form fields arranged in rows and columns like a spreadsheet.      2
The ViewsAllowed property uses the following settings.

Setting      Description      Visual Basic
Both      (Default) Users can switch between Form view and Datasheet view.      0
Form      Users can't switch to Datasheet view from Form view.      1
Datasheet      Users can't switch to Form view from Datasheet view.      2
Design view is always available (unless permissions are set otherwise).
You can set these properties by using the form’s property sheet, a macro, or Visual Basic.

Remarks

The views displayed in the View button list and on the View menu depend on the setting of the ViewsAllowed property. For example, if the ViewsAllowed property is set to Datasheet, Form View is disabled in the View button list and on the View menu.
The combination of these properties creates the following conditions.

DefaultView      ViewsAllowed      Description
Single, Continuous Forms, or Datasheet      Both      Users can switch between Form view and Datasheet view.
Single or Continuous Forms      Form      Users can't switch from Form view to Datasheet view.
Single or Continuous Forms      Datasheet      Users can switch from Form view to Datasheet view but not back again.
Datasheet      Form      Users can switch from Datasheet view to Form view but not back again.
Datasheet      Datasheet      Users can't switch from Datasheet view to Form view.
0
 
LVL 34

Assisted Solution

by:flavo
flavo earned 300 total points
ID: 10754140
and Me.DefaultView
0
 

Author Comment

by:kbutler
ID: 10754263
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
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 27

Accepted Solution

by:
jjafferr earned 200 total points
ID: 10754773
Hi kbutler,

Why Don't you have 2 Copies of your SubForm, sigle Form and Continuous Form,
and 2 copies of your main Form, i will have your single Form, the other main Form will have the Continuous SubForm,
Then use if statment on the button wich will lead the user to either.

Hope this helps

jaffer
0
 

Author Comment

by:kbutler
ID: 10754823
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!
0
 

Expert Comment

by:TomAnselmo
ID: 11032982
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
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question