Solved

Error 2046 with DoCmd.RunCommand acCmdFreezeColumn

Posted on 2007-03-20
4
1,252 Views
Last Modified: 2013-11-28
I am bringing up a subform as a datasheet inside a form.  I would like to freeze the first three columns.  I do this using code like this in the Form_Open event:

  Me.Col1.SetFocus
  DoCmd.RunCommand acCmdFreezeColumn
  Me.Col2.SetFocus
  DoCmd.RunCommand acCmdFreezeColumn
  Me.Col3.SetFocus
  DoCmd.RunCommand acCmdFreezeColumn

This used to work.  However, I added a GotFocus event to Col3 and now after executing that code, the next time it tries to execute the DoCmd statement I get Error 2046 "command isn't available".

I have tried a number of things to try and get this to work:
1) Trapped and ignored the error:  The problem is that the columns don't come up in the right order anymore.
2) Set a boolean value so that I could skip all of the code in the GotFocus event during the Open_Form event:  This doesn't work.  It seems that just going to the event even if there is no code there causes the problem.
3) Added a pause:  even with pause as long as 10 seconds this didn't work.

Is there a solution?  The only things I can think of are:
1) Is there a way to deactivate an event completely and then reactivate it?
2) Is there a way to create the event programatically?  Then I could create it after I execute the other code.



0
Comment
Question by:dastrw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
faz136 earned 400 total points
ID: 18760527
It may work if you remove the [Event Procedure] tag from the got focus line of the properties, then at the end of your code put the line col3.OnGotFocus = "[Event Procedure]"
 
I generally use this to assign functions to events at runtime
0
 
LVL 16

Assisted Solution

by:GreymanMSC
GreymanMSC earned 100 total points
ID: 18760925
faz136 has a good idea.  To prevent the on got focus event from running when you set focus to a control simply set the property to "".  Don't forget to put it back to "[Event Procedure]" when you are done.

Specifically:

  Me.Col3.OnGotFocus = ""
  Me.Col3.SetFocus
  DoCmd.RunCommand acCmdFreezeColumn
  Me.Col3.OnGotFocus = "[Event Procedure]"
0
 
LVL 2

Author Comment

by:dastrw
ID: 18765790
I'm having trouble with the syntax so when I set focus to the control it can't find the 'macro' that I created.

If my event is called Col3_GotFocus() what should I put between the double-quotes in the assignment statement?

I tried:

Me.Col3.OnGotFocus = "Col3_GotFocus"
Me.Col3.OnGotFocus = "Col3_GotFocus()"
Me.Col3.OnGotFocus = "[Col3_GotFocus]"

None of these worked.
0
 
LVL 2

Author Comment

by:dastrw
ID: 18765996
Duh!

I put the words [Event Procedure] in and it worked!

This is a great trick that I will be able to use in a lot of places.  Thanks for the help!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question