An event procedure is never called
A procedure such as Grid1_RowClick or btnSave_Click exists in the form module, but nothing
happens when the user acts on the control - no breakpoint is reached, no message box appears.
Environment
Every WKL control and object, every release, Microsoft 365 Access (full and runtime) and Excel and Word UserForms.
Cause
One of these, most frequent first:
- The form module does not compile. A module with a compile error anywhere receives no event at all, and Access reports it nowhere until the module is compiled:
DoCmd.OpenFormcalled through Automation returns without opening the form,RunCommand acCmdCompileAndSaveAllModulesraises no error. A frequent cause is a hand-typed declaration with a different number of parameters than the event has, or an enumeration type (WklUpdateAction, for example) while the reference to the WKL Forms Object Library is missing. - The form has no module. Has Module = No: Access passes no event of any control to the form. An empty module is enough.
- The action came from code. Most events report what the user does. The same change made in code -
SelectedKey = 5,Value = True,MoveNode,Requery- raises no event, likeAfterUpdateof an Access text box set by code. Exceptions are named on their member:AfterTabChangeofWklDockLayout(reasonwtcCode),FilterChipRemoved(ByUser = False) andCommandStateChangealso follow changes made by code. - A format event is switched off.
NodeFormat,RowFormatandCellFormatoccur only withFormatEvents = True(why). - The name does not match. The procedure must be named
<control name>_<event>, with the control's current name; after renaming the control, the old procedure no longer belongs to it. WithEventsinside a procedure, or the object is gone. ForWklToastandWklLinkManager, theWithEventsvariable must be declared at the top of a class or form module, and the object must still be held there (Set mToast = New WklToast) when the event occurs.- Another event procedure of the same control is still running. VBA delivers no event of an object while a procedure for an event of the same object runs. The record commands of
WklGrid(DeleteSelected,NewRecord, and so on) called inside one of its own event procedures therefore run only after that procedure has ended, so their events arrive; other events raised meanwhile are lost.
Resolution
- In the VBA editor, choose Debug › Compile <project> and fix every error it shows; then check in the Immediate window that
? Application.IsCompiledreturns True. - Set Has Module of the form to Yes.
- Create the procedure through the object and procedure lists of the code window (or the designer Events page of the tree and grid controls), so that its name and declaration are right (how-to).
- For format events, set
FormatEvents = True; for objects, move theWithEventsdeclaration to module level. - To run code after an action you trigger yourself, call your procedure directly after the statement that triggers the action.
en/wiki/msaccess/comctl/troubleshooting/event-procedure-never-called.txt · Zuletzt geändert: von Wolfgang van der Stille