how do i use VBA to change form view

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

Guest

Greetings to all.

Can anyone tell me please how to use VBA to change a subform's view from
"datasheet" to "single-form"?

Thanks for any tips.

Ben.
 
This line of code (where SubformName is the name of the control that holds
the subform object) should do that, if the subform object allows you to view
the single form view:

Me.SubformName.Form.DefaultView = 0

Note that these are the numbers (from Help file) for the different views:


Setting Visual Basic
Single Form 0
Continuous Forms 1
Datasheet 2
PivotTable 3
PivotChart 4
 
Greetings to all.

Can anyone tell me please how to use VBA to change a subform's view from
"datasheet" to "single-form"?

Thanks for any tips.

Ben.

Let's assume the master form is "frmBilling" and the sub-form name is
"frmDetails". Let's also assume you wish to stay at the same master
record after you change the sub-form view.

Add a command button to the frmBilling Form Header.
Code the button's click event:

Dim lngID As Long
lngID = Me.ID
DoCmd.Echo False
DoCmd.OpenForm "frmDetails", acDesign, , , , acHidden
If Forms!frmDetails.DefaultView = 0 Then '
Forms!frmDetails.DefaultView = 2 '
Else
Forms!frmDetails.DefaultView = 0
End If
DoCmd.Close acForm, "frmDetails", acSaveYes
DoCmd.OpenForm "frmBilling"
Forms!frmBilling!ID.SetFocus
DoCmd.FindRecord lngID, acStart, , acSearchAll
DoCmd.Echo True

The above will toggle the view between datasheet and single view.

Change [ID] to whatever the actual PrimeKey field name is.
 
Back
Top