davecocks
asked on
Switching between form views using acCmdSubformDatasheet
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
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
If that doesn't do it try this:
Me.surveyGroup.SetFocus
Me.survey.SetFocus
Me.survey.Form.SetFocus
DoCmd.RunCommand acCmdSubformDatasheet
Me.surveyGroup.SetFocus
Me.survey.SetFocus
Me.survey.Form.SetFocus
DoCmd.RunCommand acCmdSubformDatasheet
ASKER
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.F orm.SetFoc us (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?
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
Me.survey.Form.SetFocus (run time error 2449 invalid method in expression)
I tried Forms!surveyGroup.survey.F
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
You.Great!!! 1) worked like a charm!!!! That's brilliant thanks mate!
ASKER
Didn't refresh my web page fast enough! Thanks for posting another solution as well !!
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
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
Me.surveyGroup.SetFocus
Me.survey.SetFocus
DoCmd.RunCommand acCmdSubformDatasheet