Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-04
6
Medium Priority
?
813 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 34

Assisted Solution

by:flavo
flavo earned 1200 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 1200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 27

Accepted Solution

by:
jjafferr earned 800 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

661 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