Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change view of Sub-Form on Click 1

Status
Not open for further replies.

sterlecki

Technical User
Oct 25, 2003
181
US
I have a subform with a default continuous forms view. Some users prefer to see the subform in Datasheet view.

I have read some threads that suggest using two subforms and alternating between the two for the desired view. I have read that Access cannot change the view of a subform unless it is in Design view. However...

If you right click over a heading in the subform, a menu appears with a Subform item and a submenu below that which allows you to change the view to Datasheet or Form view.

This leads me to conclude that the change can be made without being in design view. How could one capture the code for these mouse operations? (ie Excel lets you record a macro this way is there a way in Access to accomplish the same?)

I would like to do this using a toggle button.

Any Thought?
 
Hi
You cannot capture mouse movements / clicks, but you can build macros.
You can do something like the above with a subform, but not with a form, because once a form is in datasheet view, there is nowhere for the change button to reside.

Code:
Private Sub cmdViewChange_Click()
'To get to the subform
DoCmd.GoToControl "SubFormName"
DoCmd.GoToControl "NameOfAFieldOnSubform"
DoCmd.RunCommand acCmdSubformDatasheet
End Sub
 
Thanks this worked just fine. I couldn't get it to work with an if statement so I could toggle back and forth. I did a work around with two diffent command buttons one visible when the other was not.

the if statement version below didn't work. The value of the me.currentview didn't change and I could not reset it.

Private Sub cmdViewChange_Click()
'To get to the subform
Dim intview as integer

DoCmd.GoToControl "SubFormName"
intview = me.currentview

If intview = 1 Then
DoCmd.GoToControl "NameOfAFieldOnSubform"
DoCmd.RunCommand acCmdSubformDatasheetView
Else
DoCmd.GoToControl "SubFormName"
DoCmd.GoToControl "NameOfAFieldOnSubform"
DoCmd.RunCommand acCmdSubformFormView
End If
End Sub


I rechecked it using this code and the current view values were one (1) from both subs

Private Sub cmdViewDS_Click()
Dim intView As Integer

DoCmd.GoToControl "frmmstrWellData"
intView = Me.CurrentView
Debug.Print intView
DoCmd.GoToControl "API"
DoCmd.RunCommand acCmdSubformDatasheetView
cmdViewDS.Visible = False
cmdViewForm.Visible = True

End Sub
Private Sub cmdViewForm_Click()
Dim intView As Integer


DoCmd.GoToControl "frmmstrWellData"
intView = Me.CurrentView
Debug.Print intView
DoCmd.GoToControl "API"
DoCmd.RunCommand acCmdSubformFormView
cmdViewDS.Visible = True

Anyway thanks again for your suggestions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top