Solved

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

Posted on 2004-04-04
6
769 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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