Any idea why code would work as intended when setting a breakpoint and stepping through it line by line, but won't work correctly at run-time?
The code is too much to post, so I hope this summary of the setup will suffice:
There are 3 forms:
A button on MainForm opens dlgForm. (dlgForm is declared as an object variable.)
If "OK" is clicked on dlgForm, a custom event is triggered in that form's Close event which switches the recordForm's recordsource to the table. The focus is (supposed to be) shifted to a control in recordForm and the following line is called to create a new record in the table:
Everything hinges on the focus being shifted to the subform.
When the code runs, the dlgForm retains the focus despite the "setfocus" commands in the event code and the "new record" command throws an error that the command is not available.
If I set a breakpoint in the dlgForm's Close event and step through the code line by line, the focus shifts as it should and all works well.
Sorry for the long post. Any ideas would be much appreciated!
The code is too much to post, so I hope this summary of the setup will suffice:
There are 3 forms:
- MainForm
- recordForm (subform on MainForm)
- dlgForm (pop-up form)
A button on MainForm opens dlgForm. (dlgForm is declared as an object variable.)
If "OK" is clicked on dlgForm, a custom event is triggered in that form's Close event which switches the recordForm's recordsource to the table. The focus is (supposed to be) shifted to a control in recordForm and the following line is called to create a new record in the table:
Code:
DoCmd.RunCommand acCmdRecordsGoToNew
When the code runs, the dlgForm retains the focus despite the "setfocus" commands in the event code and the "new record" command throws an error that the command is not available.
If I set a breakpoint in the dlgForm's Close event and step through the code line by line, the focus shifts as it should and all works well.
Sorry for the long post. Any ideas would be much appreciated!
Comment