Programmatic toggle form between FormView and Datasheet view
Rene, it does look like you are not permitted to switch views in the KeyDown
event of the form, though I'm seeing a different error message (2174):
You can't switch to a different view at this time.
As you say, the same code works elsewhere, e.g. in the Click of a command
button. Clearly that's no use for switching back out of datasheet view
again. Could you work around the issue with a toolbar button?
Allen Browne - Microsoft MVP (Most Valuable Professional)
Allen Browne's Database And Training - Perth, Western Australia.
Tips for MS Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")
> Hello group,
> This one is having me scratch my head!
> I wish to program a FunctionKey (vbKeyF9) such that when the user hits it,
> the form switches view, in a toggle fashion, from form view to datasheet
> view and back.
> I trap the user's hitting the Fkey in the form_KeyDown event. From the
> event procedure, I call a 'ToggleView' procedure. This procedure in turn
> checks the current view (Me.CurrentView), and accordingly issues either
> 1- DoCmd.RunCommand acCmdFormView or
> 2-DoCmd.RunCommand acCmdDatasheetView
> This generates runtime error 3270 - Property not found. I have no clue as
> to the reason.
> Additional info:
> I can invoke the ToggleView elsewhere, ex. from the debugging window - and
> that works fine. So it appears I can't switch views from within an event
> handler in the form.