Solved

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

Posted on 2004-04-04
6
752 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

21 Experts available now in Live!

Get 1:1 Help Now