Changing Form View with VBA

  • Thread starter Thread starter Chegu Tom
  • Start date Start date
C

Chegu Tom

I have a form (with a subform) that opens in datasheet view. Working in
Access 2000

I would like to use a click or double click event to switch to form view
and back to datasheet of the open form

I can't find the object or method to do this.

Thanks
 
Chegu Tom said:
I have a form (with a subform) that opens in datasheet view. Working in
Access 2000

I would like to use a click or double click event to switch to form view
and back to datasheet of the open form

I can't find the object or method to do this.


It's not obvious. For a main form, you could write this code in the
appropriate event:

'----- start of code -----
If Me.CurrentView = 1 Then
RunCommand acCmdDatasheetView
Else
RunCommand acCmdFormView
End If

'----- end of code -----

For a subform -- if you want to switch the subform *only* between form view
and datasheet view -- the simple statement "RunCommand acCmdSubformDatasheet
toggles between form view and datasheet view of the subform. But you have
to make sure the focus is on the subform you want to affect, like so:

Me.sfMySubform.SetFocus
RunCommand acCmdSubformDatasheet
 
Dick

"It's not obvious" you say!

That's why people like you are so valuable. Thanks for being here!

Tom
 
Back
Top