Link to home
Start Free TrialLog in
Avatar of Jerry N
Jerry NFlag for United States of America

asked on

Access 2010 Error 2046: RunCommand acCmdDatasheetView (Find)

I'm running a form that is based on a linked table.
Simple form, just two text boxes.
I have a routine that looks like this:

Sub Listit(sFormName As String)
If Forms(sFormName).CurrentView = 1 Then
   DoCmd.RunCommand acCmdDatasheetView
Else
   DoCmd.RunCommand acCmdFormView
End If

I pass the Me.name but it's giving me a 2046 that it cant do that right now.

It also does the same thing when I try to use the RunCommand on FIND.
I had been using the menu type commands in 2003, but thought this would be cleaner and work better.

Any clue on fixing this?
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

You cannot change a forms View at runtime.

You have to close the form, then reopen it with the new view setting
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jerry N

ASKER

I'll give it a try - Makes sense.
What about FIND - doesnt that just popup a find interface?  why would I get the error there?
There are just certain times when a certain command is not possible.
So you have to be clear on when/how you are running these codes

Also note that spell check will not work if the Allow edits property is set to No.

JeffCoachman
...and to close out, I will say that what I posted is more of a brute force solution...
...not sure why you need to change the view dynamically...?