473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Change form view using VB after the form is opened?

jamjar
50
How do I change the form view using VB after the form is opened?

I am using the Switchboard pretty much as the wizard loads it. I've tweaked the appearance and a couple of lines of code but I don't want to modify it too much.

When I try to load a form with the properties set to load as Datasheet view only, the switchboard's VB code overrides these settings and loads it in Form view.

Can I use VB in the Form_Open or some other event to change the view back to datasheet?

I'm using Access 2002 ....

James
Jun 1 '07 #1
10 39316
MMcCarthy
14,534 Expert Mod 8TB
How do I change the form view using VB after the form is opened?

I am using the Switchboard pretty much as the wizard loads it. I've tweaked the appearance and a couple of lines of code but I don't want to modify it too much.

When I try to load a form with the properties set to load as Datasheet view only, the switchboard's VB code overrides these settings and loads it in Form view.

Can I use VB in the Form_Open or some other event to change the view back to datasheet?

I'm using Access 2002 ....

James
For the form being opened change the properties under the format tab of Default View and Views Allowed so both are set to Datasheet.
Jun 1 '07 #2
jamjar
50
For the form being opened change the properties under the format tab of Default View and Views Allowed so both are set to Datasheet.
I tried this and it still opens in Form view instead of Datasheet view. I think this is because the VB code created by the Switchboard wizard:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm rs![Argument], , , , acAdd
causes it to open in Form view even if the defaults and allowable views are set otherwise, and even thought the 2nd argument does not specify a view.
When I set the second argument to 'acFormDS' the sheet will open in Datasheet mode, but I don't want this for most forms.
I don't know why the VB code would cause the form to open ignoring the set properties even when a view is not specified, but it does. So I'm left wondering if I can change the view in the form's OnOpen event?

James
Jun 6 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
I tried this and it still opens in Form view instead of Datasheet view. I think this is because the VB code created by the Switchboard wizard:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm rs![Argument], , , , acAdd
causes it to open in Form view even if the defaults and allowable views are set otherwise, and even thought the 2nd argument does not specify a view.
When I set the second argument to 'acFormDS' the sheet will open in Datasheet mode, but I don't want this for most forms.
I don't know why the VB code would cause the form to open ignoring the set properties even when a view is not specified, but it does. So I'm left wondering if I can change the view in the form's OnOpen event?

James
Not in the open event but maybe in the Load event. Let me check.
Jun 6 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
Not in the open event but maybe in the Load event. Let me check.
Sorry I'm afraid none of the events that trigger when you open the form will allow the view to be changed.

Maybe someone else will have some ideas.
Jun 6 '07 #5
jamjar
50
Sorry I'm afraid none of the events that trigger when you open the form will allow the view to be changed.

Maybe someone else will have some ideas.
Thanks Mary. Since you usually know the answers if they exist ;-) I decided to proceed as if it doesn't .... I had the idea that if is not opened as a datasheet, I force the form to close and re-open properly:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.   Dim str As String
  3.     If Me.CurrentView <> 2 Then
  4.         'if not opened as a datasheet, close and re-open in datasheet view
  5.         str = Me.Name
  6.         DoCmd.Close acForm, str
  7.         DoCmd.OpenForm str, acFormDS
  8.         Exit Sub
  9.     End If
  10. End Sub
This seems rather brutal but it works!

James
Jun 6 '07 #6
MMcCarthy
14,534 Expert Mod 8TB
Thanks Mary. Since you usually know the answers if they exist ;-) I decided to proceed as if it doesn't .... I had the idea that if is not opened as a datasheet, I force the form to close and re-open properly:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim str As String
  3.     If Me.CurrentView <> 2 Then
  4.         'if not opened as a datasheet, close and re-open in datasheet view
  5.         str = Me.Name
  6.         DoCmd.Close acForm, str
  7.         DoCmd.OpenForm str, acFormDS
  8.         Exit Sub
  9.     End If
  10. End Sub
This seems rather brutal but it works!

James
I'm surprised it works as once the form closes the code should lose focus. However, if it works go with it.

Mary
Jun 6 '07 #7
jamjar
50
I'm surprised it works as once the form closes the code should lose focus. However, if it works go with it.

Mary
It is ugly. I was afraid the code would cease when the form was closed but apparently not.

James
Jun 7 '07 #8
FishVal
2,653 Expert 2GB
It is ugly. I was afraid the code would cease when the form was closed but apparently not.

James
Think different.

1) Add field [FormView] to the [Switchboard] table and store there number equal to VBA constant (acNormal=0, acFormDS=3)
2) In Switchboard form module replace
DoCmd.OpenReport rs![Argument]
to
DoCmd.OpenReport rs![Argument], rs![FormView]

To my mind this is much easier than to add OnOpen event to each form.

By the way you can switch form view programmatically using
DoCmd.RunCommand acCmdDatasheetView
But this fails in OnOpen, OnLoad, OnActivate, OnCurrent events handlers when form is being opened.

Good Luck
Jun 7 '07 #9
jamjar
50
Think different.

1) Add field [FormView] to the [Switchboard] table and store there number equal to VBA constant (acNormal=0, acFormDS=3)
2) In Switchboard form module replace
DoCmd.OpenReport rs![Argument]
to
DoCmd.OpenReport rs![Argument], rs![FormView]

To my mind this is much easier than to add OnOpen event to each form.

By the way you can switch form view programmatically using
DoCmd.RunCommand acCmdDatasheetView
But this fails in OnOpen, OnLoad, OnActivate, OnCurrent events handlers when form is being opened.

Good Luck
Thanks.
I would modify the Switchboard but I just went through a conversion from 97 to 2002 and had problems with migrating the switchboard over, and I had to start over using the 2002 Switchboard wizard and re-doing the form style, controls and the couple of code changes I had made. So I'd rather not tweak it more than I already have in case the same thing happens when the next conversion comes along (which in my case could just as likely be back to 97, but that's a long story).
Jun 8 '07 #10
I'm no programmer, but I used google to find an answer to this same problem and found this page - which didn't help directly, except to inspire me to look at my main menu form itself, as I have a button there from which we open the form we need to use in datasheet view.

Here's what I did:
(My apologies if you the answer is already in techspeak above.)

1. Opened the menu form in design view
2. Opened Property Sheet for the Command Button
3. Under Event tab, clicked "..." by "On Click [Embedded Macro]"
4. Under Action Arguments, View, selected Datasheet

Voila!
Oct 1 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Simon Pleasants | last post by:
Am something of a newbie at this, so please bear with any stupid questions. I have created a database to track shipments that we import. The information is stored in a table and I have created...
2
by: j.mandala | last post by:
This had got to be something obvious that I am too blind to see! Funny problem: one of my users has my application linked to a SQL Server Backend. Front end it Access XP (SP3). The first form...
5
by: Susan Bricker | last post by:
Hi. I have a friend who has a form (ok that's a lie ... it's me that has the form) that is opened up with AllowAdditions and AllowEdits = TRUE and the selection criteria for the form results in 2...
9
by: David White | last post by:
Hello everyone, I'm new to access, so if this is a dumb question I apologize in advance. I created a query that requires a "parameter value" to be entered. I then created a form to display...
2
by: MLH | last post by:
A97 Am having difficulty displaying graph in Form View that I see fine in graph control on form opened in design view. I know I'm doing something wrong. If I open the form in design view - I...
15
by: kokostik | last post by:
I did a few searches, but couldn't come up with a clear answer to my question. So here it is: If I am in an open form (MyForm1), is it possible to set the RecordSource of an un-opened form...
2
by: ConfusedMay | last post by:
I have a form that content all sales. Right now the default view is single form. the problem is that I can't view the form as a datasheet view when I run the form, even I already specified on the...
3
by: mckbill | last post by:
Is there a way I can direct the cursor to a specific field (variable) in a form by typing the field name while in form view? I have a form with many fields, and it would be nice if there were...
4
by: soulerrant | last post by:
Access 2003 SP2, Win XP I have a form that has Default View = Datasheet; allow Form View = No. Form opens in Datasheet view. The form has a text field with 'Is Hyperlink' set to Yes. When the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.