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 12th, 2005, 08:56 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Okay, I'll take a stab at it... Not knowing exactly how you set up your form, that's the best I can do.

Did you put the toggle button on the main form or the sub form?

I'm guessing you put it on the subform because that's what I tried and I get what I believe is the same error you get. (I too have a database just for this forum.)

In case that's what you did, I wonder what you did with the SetFocus statement from my sample code. The reason for the SetFocus method to set focus to the subform is the button is supposed to be on the main form. If the button is in the subform I think the reason you can't change the view is because you're running code in the form.

I can't think of anything else that would be the cause. So you're on your own unless we take this off-line and you send me your database. If you follow the PNWADG link, you'll find a mailbox where you can contact me.

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

Randall,
The command button to switch the form is on the main form.
Here's my code behind the button:
Private Sub Command38_Click()
On Error GoTo Err_Command38_Click
    Dim myform As Form
    Set myform = Forms![Report Generator].[Text Table].Form
    myform.SetFocus
    myview = myform.CurrentView
    If myview = 1 Then
       DoCmd.RunCommand acCmdsubformDatasheetView
    Else
       DoCmd.RunCommand acCmdsubformFormView
    End If

Exit_Command38_Click:
    Exit Sub

Err_Command38_Click:
    MsgBox err.Description
    Resume Exit_Command38_Click

End Sub


Thanks,
Kevin

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

I'm not sure what you're up to.

By creating the form object variable in your procedure, you're not looking at a subform -- at least not the way I think about it. I thought about trying to recreate your setup to debug it and explain what you're getting. But I think we should be clear we're talking about the same thing.

Suppose you have "frmMain", your main form, and "fsubForm" as your sub form.

On "frmMain" you create a button, name it "cmdChangeView". Then you create a subform object on "frmMain" (using the subform object from the Toolbox). If you use the Toolbox wizard to create the subform, it will automatically name the object "fsubForm". If you're not using the wizard, name it that.

Then your code in frmMain is:

Private Sub cmdChangeView_Click()

dim intCurrView as integer
intCurrView = me.fsubForm.Form.CurrentView
me.fsubForm.SetFocus
if intCurrView = acCurViewFormBrowse then
    DoCmd.RunCommand acCmdsubformDatasheetView
Else
    DoCmd.RunCommand acCmdsubformFormView
End If

End Sub

A couple of notes:
1) I don't add error trapping until I know the code works. Access error messages are more complete than the error traps I write. (That's not completely true. But the error trap routine I have puts a record in a table. I don't need to do that while I'm debugging code.)
2) I try to use the Ac constants (e.g. acCurViewFormBrowse) because they are more descriptive than "1".

FWIW, you're probably getting the error because of something like:
- your form object isn't visible
- your form isn't actually a subform
- you may actually be getting the error from the SetFocus statement (another reason not to do error trapping while you're debugging code)
- you should have either defined
Dim myForm as New Form
and did the set statement as is, or Dim the way you did and do
Set myForm = New ...
This may be the reason you're not able to SetFocus.

Any more debugging your code and I'm going to have to send you a bill. ;)

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

That got it! Thanks Randall.

dartcoach
 
Old March 13th, 2005, 07:33 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

I used Randall's Original code with minor additions...
This is from an event click from a toggle button on the main form.

sub_Order.SetFocus
    If Toggle33.Value = True Then
       DoCmd.RunCommand acCmdSubformFormView ' set to form view
    Else
       DoCmd.RunCommand acCmdSubformDatasheet ' set to datasheet view
     End If
End Sub

'note ... in the main form load I set Toggle33.Value = False or True for initializaztion purposes. If its not set immediately on load, it takes two clicks to get it in a true or false state.


Marc Noon

Coding is a game. Live it, love it, break it, run it.





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.