Solved

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

Posted on 2004-04-04
6
758 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now