Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Switching between form views using acCmdSubformDatasheet

Posted on 2009-07-01
8
Medium Priority
?
1,111 Views
Last Modified: 2013-11-28
Hi,

Form:                  surveyGroup
Subform             survey
sub-subform       boatTransects

I have a button on the surveyGroup form that switches the view of 'survey' from data sheet to subform view.

The following code works, but when I click the mouse 'flashing cursor'  into a textbox on 'boatTransects' and the button is then clicked, the 'boatTransects' form toggles between subform view and datasheet view NOT the 'survey' form.

What I need to do is get the reference right so that the focus is always on the 'survey' form and therefore gets its view changed regardless of where the cursor is clicked on the other sub-subforms.

Thanks


Private Sub btnView_Click()
If Forms!surveyGroup.survey.Form.surveyTypeID.Value = 2 Then
  'MsgBox "is Land"
  Me.survey.Form.subform_boatTransects.Visible = False
  Me.survey.Form.subform_LandSightings.Visible = True
 
'Swaps the view 
   Me.survey.SetFocus
    DoCmd.RunCommand acCmdSubformDatasheet
    Me.surveyDate.SetFocus
Else
  'MsgBox "is Boat"
  Me.survey.Form.subform_boatTransects.Visible = True
  Me.survey.Form.subform_LandSightings.Visible = False
 
  'Swaps the view 
  Me.survey.SetFocus
  DoCmd.RunCommand acCmdSubformDatasheet
 Me.surveyDate.SetFocus
End If
End Sub

Open in new window

0
Comment
Question by:davecocks
[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
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:thenelson
ID: 24753514
try this:
  Me.surveyGroup.SetFocus
  Me.survey.SetFocus
  DoCmd.RunCommand acCmdSubformDatasheet
0
 
LVL 39

Expert Comment

by:thenelson
ID: 24753525
If that doesn't do it try this:
  Me.surveyGroup.SetFocus
  Me.survey.SetFocus
  Me.survey.Form.SetFocus
  DoCmd.RunCommand acCmdSubformDatasheet
0
 
LVL 1

Author Comment

by:davecocks
ID: 24761816
Hey,
Thanks for the reply.     I tried both but no joy.

access didin't like       Me.surveyGroup.Setfocus         (method or group not found)
I tried                          Forms!surveyGroup.Setfocus      (worked)

                                  Me.survey.Form.SetFocus      (run time error 2449 invalid method in expression)
I tried     Forms!surveyGroup.survey.Form.SetFocus   (run time error 2449 invalid method in expression)

That left        Forms!surveyGroup.SetFocus
                      Me.survey.SetFocus

Which worked but didn't solve the problem of of the other forms changing.  

Any other ideas?
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 39

Accepted Solution

by:
thenelson earned 2000 total points
ID: 24761859
Me.surveyGroup.Setfocus   Oops, Sorry.   Me.Bad

1. Try setting the focus to a control in survey:
  Me.survey.SetFocus
  Me.survey!MyControl.SetFocus
  DoCmd.RunCommand acCmdSubformDatasheet

2. Is survey the name of the subform container or the name of the form in the container? If they have the same name, try changing the container to ctnSurvey and use
Me.ctnSurvey.SetFocus
DoCmd.RunCommand acCmdSubformDatasheet
0
 
LVL 39

Expert Comment

by:thenelson
ID: 24762056
I got it.  Place:
DoCmd.RunCommand acCmdSubformDatasheet
in the on enter event of the container for survey SubForm.  

So it only fires when You want it to create a public variable in the main form surveyGroup:

In surveyGroup:
Public CreateDataSheet As Boolean

In survey:
Private Sub ctnsurvey_Enter()
If CreateDataSheet Then DoCmd.RunCommand acCmdSubformDatasheet
CreateDataSheet = False
End Sub

In your Code:
CreateDataSheet = True
Me.survey.SetFocus



0
 
LVL 1

Author Closing Comment

by:davecocks
ID: 31598710
You.Great!!!   1) worked like a charm!!!!  That's brilliant thanks mate!
0
 
LVL 1

Author Comment

by:davecocks
ID: 24762113
Didn't refresh my web page fast enough!  Thanks for posting another solution as well !!
0
 
LVL 39

Expert Comment

by:thenelson
ID: 24762228
I ran into a problem with 1 so that's why I came up with another.

Also figured out what was going on. When you enter a subform, the control in it that last had focus still has the focus. When you clicked on the boatTransects subform, it's container got the focus in the subform. Clicking on the button changed the focus to surveyGroup main form but when you changed the forces to survey, the boatTransects subform container still had the focus within survey.

You're welcome.  Glad to help and thank you very much for the points with "A" grade!  It was a fun one!

Happy Computing!

Nelson
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

610 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