Switch between Datasheet and Form view

M

makulski

I have a subform that I want to be able to switch between datasheet view and
form view.

I can right click to get subform which shows the two views (I have the
properties set to allow only the two views, with the default view being the
form view).

Is there any way to do this programatically?
I'd like to put a toggle button right on the form.
But I can't change the default view property after the subform is already
open.

What am I missing here?
Thanks.
 
U

UpRider

Set the <subform> default view to 'single form', and set 'allow datasheet
view' and 'allow form view' to YES. Then when viewing the main form, right
click on the subform. Click the top menu item and choose your view.
(AC2007)

HTH, UpRider
 
M

makulski

Yes, thanks, but, perhaps I wasn't clear.
I know how to right-click-select off a menu.
What I'd like to do is put a button on the form that does this (to avoid all
the right-clicking etc.)
 
U

UpRider

OK. You need two subforms, one datasheet view, the other form view. They
are exactly alike except for the view properties. Lay one on top of the
other in the main form (Don't put one subform inside the other subform,
easy to do by mistake). Set the linkage to the main form identical,
recordsource identical, etc. But have the <controls> holding the subforms
named, say
ctlFormView and ctlDSView.

Put a togglebutton named tglSwitch on your main form. Code its afteupdate
event as:
Private Sub tglSwitch_AfterUpdate()
Select Case tglSwitch.Value
Case True
ctlDSView.Visible = False
ctlFormView.Visible = True

Case False
ctlDSView.Visible = True
ctlFormView.Visible = False
End Select
End Sub

It's a bit of a kludge, but it works.

HTH, UpRider
 
P

Paul Shapiro

From the main form, use code like this to change the subform mode:
'If subform is not in Datasheet View, set it to Datasheet View
If Me.subFeeAdjustments.Form.CurrentView <> acCurViewDatasheet Then
Me.subFeeAdjustments.SetFocus
Me.subFeeAdjustments.Form.cboAdjustmentType.SetFocus
Access.RunCommand acCmdSubformDatasheetView

'Put focus back where we want it
Me.pageEventItems.SetFocus
Me.cboParticipant.SetFocus
End If
 
U

UpRider

Good code. Works great, Paul.

Paul Shapiro said:
From the main form, use code like this to change the subform mode:
'If subform is not in Datasheet View, set it to Datasheet View
If Me.subFeeAdjustments.Form.CurrentView <> acCurViewDatasheet Then
Me.subFeeAdjustments.SetFocus
Me.subFeeAdjustments.Form.cboAdjustmentType.SetFocus
Access.RunCommand acCmdSubformDatasheetView

'Put focus back where we want it
Me.pageEventItems.SetFocus
Me.cboParticipant.SetFocus
End If
 
M

makulski

Beautiful.
I used your code as a jump start to this, which does exactly what I want:

Private Sub Command6_Click()
'Toggles between DataSheet view and Form view
Me.subMsgMap.SetFocus

Select Case Me.subMsgMap.Form.CurrentView
Case acCurViewFormBrowse
Access.RunCommand acCmdSubformDatasheetView
Me.Command6.Caption = "Sheet View"
Case acCurViewDatasheet
Access.RunCommand acCmdSubformFormView
Me.Command6.Caption = "Form View"
End Select
'Put focus back where we want it
Me.Command6.SetFocus
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top