Change a Sub Form View

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Master Form with a subform. When the master form opens, the subform
is in continuous forms view. I am trying to put a button on the master Form
- that
on click i would like to change the Subform to datasheet view. and of course
reset it back to continuous forms with another button.

Any suggestions would be appreciated -
 
canusehelp said:
I have a Master Form with a subform. When the master form opens, the
subform is in continuous forms view. I am trying to put a button on
the master Form - that
on click i would like to change the Subform to datasheet view. and of
course reset it back to continuous forms with another button.

Any suggestions would be appreciated -

You can easily use one button to toggle the modes, because the same
command toggles a subform between form view and datasheet view. For
example:

'----- start of code -----
Private Sub cmdToggleSubformView_Click()
Me.sfMySubform.SetFocus
Application.RunCommand acCmdSubformDatasheet
Me.cmdToggleSubformView.SetFocus
End Sub

'----- end of code -----
 
This is kinda messy to program. It requires changing focus (back to the
subform), saving any changes, and there are still cases where Access is not
happy about changing view.

How about using a toolbar button instead? That's code-free and dead simple.
 
Dirk , in using that code - as soon as it hits the Application.RunCommand
Runtime erro 2046 - The commnd or action isnt available.

Allen, I was trying to use a custom menu bar with just views - datasheet and
form
problem is that i want to allow them to move the columns around in the
datasheet view - and after they return to form view - reset the columnorder
back to the original order - everytime i attempt this - it says ya cant do it
will in form view
 
canusehelp said:
Dirk , in using that code - as soon as it hits the
Application.RunCommand Runtime erro 2046 - The commnd or action isnt
available.

Is the AllowDatasheetView property set to Yes for the form that is the
subform's source object?
Allen, I was trying to use a custom menu bar with just views -
datasheet and form
problem is that i want to allow them to move the columns around in the
datasheet view - and after they return to form view - reset the
columnorder back to the original order - everytime i attempt this -
it says ya cant do it will in form view

Since you directed this question to Allen, I'll let him answer it. <g>
But I think the trick is going to be to detect the act of switching back
to form view from datasheet view, and resetting the ColumnOrder property
for all fields before you switch views.
 
Dirk Goldgar said:
Since you directed this question to Allen, I'll let him answer it. <g>
But I think the trick is going to be to detect the act of switching
back to form view from datasheet view, and resetting the ColumnOrder
property for all fields before you switch views.

I couldn't resist (sorry, Allen). Here's an example:

'----- start of code -----
Private Sub cmdToggleSubformView_Click()

With Me.sfMySubform.Form
If .CurrentView = 2 Then
!FirstField.ColumnOrder = 1
!SecondField.ColumnOrder = 2
!ThirdField.ColumnOrder = 3
End If
End With

Me.sfMySubform.SetFocus
Application.RunCommand acCmdSubformDatasheet
Me.cmdToggleSubformView.SetFocus

End Sub
'----- end of code -----

There's probably a way to loop through the controls and reset their
column order without listing them one per statement, but this is only a
quick example, after all.
 
Back
Top