Code works on step-through but fails on run!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

With one particular form, this procedure works on step-through but fails on
run:
Private Sub CancelBttn_Click()
DoCmd.Close
Call ToggleStaffDropDn("Off")
Call ToggleBttn("Zero")
End Sub

The Toggle... items are utility procedures which reset some controls on the
Main form (which opened the failing form.) I use them repeatedly elsewhere.

The error message says the "expression requires that the control be in the
active window."

The exact same Cancel procedure works every time on another, very similar
form. I have this problem only with one form. I have added a line to set
the focus to the Main form, but it didn't help.

I am at a loss on this! Where could the problem lie?

Thanks!
 
LongWayFromHome wrote in message
With one particular form, this procedure works on step-through but
fails on run:
Private Sub CancelBttn_Click()
DoCmd.Close
Call ToggleStaffDropDn("Off")
Call ToggleBttn("Zero")
End Sub

The Toggle... items are utility procedures which reset some controls
on the Main form (which opened the failing form.) I use them
repeatedly elsewhere.

The error message says the "expression requires that the control be
in the active window."

The exact same Cancel procedure works every time on another, very
similar form. I have this problem only with one form. I have added
a line to set the focus to the Main form, but it didn't help.

I am at a loss on this! Where could the problem lie?

Thanks!

If it relates to this code, it might be because you don't specify whicb
form to close.

DoCmd.Close acForm, Me.Name

Regarding the togglet hingies, if the setfocus doesn't work, then
another guess could be that there are something in some events in this
form which is triggered by the closing of the form (for instance before
update, after update, on unload, on close...), which forces the focus
to this form, or at least away from your main form.
 
have you tried closing the form after calling the functions?

Private Sub CancelBttn_Click()
Call ToggleStaffDropDn("Off")
Call ToggleBttn("Zero")
DoCmd.Close

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top