error while form opens

prasadgov

Member
Local time
Today, 10:58
Joined
Oct 12, 2021
Messages
120
Hi,

I inherited a database.
When I click Edit on this button, I am getting an error on this line,

DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

1722950167880.png


I did a compact and repair assuming this fe was corrupted. But it did not resolve the issue. It has linked tables to the Access be. t is driving me crazy.
What might be the issue?

TIA
 
Click the debug button? See the code….
 
The DoMenuItem was the old method of running menu items. Try replacing them with the appropriate RunCommand method.
 
The DoMenuItem was the old method of running menu items. Try replacing them with the appropriate RunCommand method.
what is the equivalent of
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70 in RunCommand method? I need the forma to open to in Edit mode
I tried,DoCmd.RunCommand acCmdFind but still get the same error
 
Last edited:
And what is that button meant to do when cliciked?
 
Have you tried CoPilot or Chatgpt? Just suggesting that some "definition type" questions might be answered quickly via Google/Chatgpt.


Question: (to CoPilot)
In MS Access what is the corresponding RunCommand equivalent for DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70?

Response:

The RunCommand equivalent for DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70 in MS Access is:

DoCmd.RunCommand acCmdFind
The DoCmd.RunCommand method is a more modern and preferred way to execute commands in MS Access12. If you have any other questions or need further assistance, feel free to ask!
 
You didn't tell us which version of Access you are running. The "10" represents a command constant that is at least potentially version dependent. What command does it represent? And is there any other code behind the button you clicked that could possibly involve a FIND operation?

EDIT: jdraw found the command, which is a FIND operation. Rather obviously, you can't do that in the way you are doing it. I would think that a FIND would require a target to be found.
 
I inherited a database.
When I click Edit on this button, I am getting an error on this line,
Sounds like you are using a different version of Access than what the database was developed with. Normally (unless MS breaks something) applications don't just stop working but menus change over time so this kind of problem arises. Try posting all the code in the module and maybe a picture of the form. The find command requires other arguments which we don't have enough information to even guess at.
 
Thank you all. I found what was causing the issue. It was a data corruption issue.
 
The Application interface functions (Runcommand or DoMenuItem) are both heavily based on focus. When you change focus to different objects the available menu items become available/Unavailable. That error is exactly what it says. The function is not available. This is easy to see. Anything in grey is NOT AVAILABLE.

Not Available.png


So in this case depending on what has the focus, I cannot delete but I can cut, copy, and paste. If you change windows or focus other menu choices become NOT AVAILABLE.

However if you can do something directly do that. Many of the functions control the UI and there is no equivalent, but others can be replaced simply using VBA objects directly.
Instead of Docmd.runcommand acCmdRecordsGoToFirst use the MoveFirst of the recordset directly. Instead of using the runcommand to set focus simply Me.someTextbox.setfocus
 
I do not think it would be going too far to even say that it's a good idea to stay away from methods that are heavily context-dependent about having the focus if there is an alternative, which there is in this case.

It's analogous to using Selection and Activate in excel vba, which there is always a better way instead
 
I do not think it would be going too far to even say that it's a good idea to stay away from methods that are heavily context-dependent about having the focus if there is an alternative, which there is in this case.

It's analogous to using Selection and Activate in excel vba, which there is always a better way instead
There is another caveat. Even in the case where there is no alternative, you still need to ensure the focus. I have seen code with unexpected actions, and it just depends on what the user was doing. These can be really hard to debug. When using the Docmd I rarely do not include the optional default parameters. Simple example
Docmd.close
When you specifically mean to close the current form, I will fully specify
Docmd.close AcForm, Me.name

In the above example it was closing another object if you got into a specific set of conditions.
 

Users who are viewing this thread

Back
Top Bottom