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?
GNOVAKAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
You cannot change a forms View at runtime.

You have to close the form, then reopen it with the new view setting
0
Jeffrey CoachmanMIS LiasonCommented:
So try it like this perhaps:

Sub Listit(sFormName As String)
If Forms(sFormName).CurrentView = 1 Then
   Docmd.close
   DoCmd.OpenForm "Yourform", acFormDS
Else
   Docmd.Close
   DoCmd.OpenForm "Yourform", acNormal
End If

JeffCoachman
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GNOVAKAuthor Commented:
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?
0
Jeffrey CoachmanMIS LiasonCommented:
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
0
Jeffrey CoachmanMIS LiasonCommented:
...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...?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.