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.