The following example turns subdatasheet expansion on or off for the "Purchase Orders" form.
To try this example yourself, open a form (containing a subform) in Design view, click the Builder button next to the On Load property box in the form's property window, paste this code into the form's Form_Load event (removing the reference to the "Purchase Orders" form), and then open the form in Datasheet view.
Dim strExpand As String
With Forms("Purchase Orders")
strExpand = InputBox("Expand subdatasheets? Y/N")
Select Case strExpand
.SubdatasheetExpanded = True
.SubdatasheetExpanded = False
MsgBox "Can't determine subdatasheet expansion state."