Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2005, 04:46 PM
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to mnoon Send a message via MSN to mnoon Send a message via Yahoo to mnoon
Default Subform - Dynamically Setting

Hi.. I have a subform under a main form. I'm trying to use a button to change it from regular form view to a datasheet view. I thought this was simple, but am having trouble finding documentation.

Also I wanted the button to toggle if possible to change it back to form view.

Thanks for any help,

Marc Noon

Marc Noon

Coding is a game. Live it, love it, break it, run it.
__________________
Marc Noon

Coding is a game. Live it, love it, break it, run it.
 
Old March 11th, 2005, 05:20 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Marc,
I've been playing with it, but can't find a way to do it either. You have another option. Create a copy of your subform, change the view to datasheet but leave everything else the same. Put it on your main form in exactly the same spot. Set the visible property on the datasheet copy to false. On your main form put a command button that checks to see which one is visible and then switch them. Be sure to refresh each one as you switch back and forth, so any changes made are reflected when they switch. Also, for your own documentation purposes make sure you don't forget there are two subforms, one on top of the other.

Kevin

dartcoach
 
Old March 12th, 2005, 11:56 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

I haven't written the code to do this myself. But this is what a buddy told me he does...

He has a toggle button. In the after update event he has something like this:

subform.SetFocus
if [toggleon] then
   docmd.RunCommand acCmdSubformDatasheet ' set to datasheet view
else
   docmd.RunCommand acCmdSubformFormView ' set to form view
end if

BTW, the buddy is working on a killer Access app. It's worth checking out if you have a few minutes. http://www.businessofficesynergy.com

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
 
Old March 12th, 2005, 05:40 PM
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to mnoon Send a message via MSN to mnoon Send a message via Yahoo to mnoon
Default

Both of those work great. Now I wander if one is more efficient?

Marc Noon

Coding is a game. Live it, love it, break it, run it.
 
Old March 12th, 2005, 05:44 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Marc,
Randall's solution is better. You don't have to have 2 forms.

Kevin

dartcoach
 
Old March 12th, 2005, 07:07 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Randall,
I've plugged your code in and I get an error message saying:
the command accmdsubformdatasheetview in not available at this time.

Am I missing a reference somewhere?

Kevin

dartcoach
 
Old March 12th, 2005, 07:40 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Kevin,

You might be missing "Office11\MSACC.OLB" (Access 2003) or "Office10\MSACC.OLB" (Access XP). ;) The option isn't available in Access 9. However, I think the Access 2000 parameter is acCmdSubformDataSheet. However, I don't know if acCmdFormView will switch it back.

Oh yeah. The other thing is that you do have to set focus to the sub form. I don't think you can run that command from the immediate window. You will have trigger the code while you are viewing the form.

TIP: try typing in DoCmd.RunCommand into VB and use intellisense. Or use F2 to display the object browser. Search for RunCommand and follow the link to AcCommand in the object definition window.

TIP: RunCommand allows access to just about any Access menu option.

BTW, you didn't mention why one form is better than 2... because you don't have to keep the two forms in sync if you make changes to your design.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
 
Old March 12th, 2005, 07:45 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Randall,
I've got that reference. Still getting the error.
You're right, I should have mentioned why 1 form is better than 2.

Kevin

dartcoach
 
Old March 12th, 2005, 08:30 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Kevin,

You're going to have to help me out a little. Which version of Access?

In the meantime, try checking the form properties "Format" tab on the subform. In 2003 there are options to "Allow [Form View|Datasheet View|...]". In 2000 there is a "Views Allowed" option which can be "Form", "Datasheet" or "Both".

Make sure the subform allows the appropriate options.

BTW, the reason for the ;) in my post was a joke about referring to an object that is always referenced in Access. I was teasing that you might be using Access 2000 which doesn't have the same options for the RunCommand.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
 
Old March 12th, 2005, 08:34 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

No problem. I'm using Access 2003. I've been creating a database that all I use it for is to play with stuff from this forum. That way, I've always got the code if I ever need it. The views allowed setting is both.

Thanks,
Kevin

dartcoach





Similar Threads
Thread Thread Starter Forum Replies Last Post
setting public strings dynamically havey C# 16 January 20th, 2008 12:04 PM
Setting Gridview Dynamically copelanda BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 February 21st, 2007 01:28 PM
setting subform to new record skinny Access 4 January 3rd, 2006 02:57 PM
Dynamically Setting X, Y Coordiantes of Element hugh@kmcnetwork.com Javascript 4 August 21st, 2005 05:01 AM
Setting stylesheet for dynamically created object tgopal Javascript 2 September 6th, 2004 11:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.