Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Posts
    369
    Thanks
    2
    Thanked 1 Time in 1 Post

    Event timing and 2585 errors (2000sp3)

    (Edited by HansV to remove superfluous line ends.)

    I'm trying to close a form as part of the on exit event of a control on the form, and receiving 2585 - can't close when processing form or report errors. Attempting to work around this, I have tried the following:

    1) Setting the focus to a dummy command button in the last line of the onexit code, and then using the btnclick routine to close the form. I've tried both calling the btnclick routine directly (when the routine runs, but still gives 2585 errors) from the btnonenter code, and sendkeys("{ENTER}"),<tried both TRUE and FALSE> from the btnonetner code, when the btnclick code doesn't even run (which I don't understand - form keypreview is on, but the formkeydown event, which just sets a flag, doesn't run either, and I thought key events did pass through to the controls after the form anyway). I tried to use the btnkeypress event instead of the btnclick event, but that didn't fire either. I've also tried both these methods from the btngotfocus code, with the same unsuccessful outcomes.

    2) Setting the focus to a dummy text box in the last line of the onexit code, changing the value of the txtbox in its ongotfocus (also tried onenter) code, and then trying to close the form from the txtbox beforeupdate (also tried afterupdate and onchange) code, which didn't work as those events didn't fire, even when I tried sendkeys("{ENTER}"),[again tried with both TRUE and FALSE] after changing the txtbox value.

    One key point about all these problems is that once the code on the dummy button or txtbox has run, stepping through the code always takes one back to the original control onexit code - even though the only remaining line is exit sub, and the focus should have passed already. Is this the problem? When does the onexit event actually finish?

    I seem to have a separate problem in that Sendkeys doesn't seem to work.

    I can't put this code in the before or afterupdate event of the original control: this control is key to the functioning of the form, and often has it's value modified by other code, but I need the onenter event of the code to fire before the onexit event, and to control the occurence of these events independently of the value of the control changing.

    Thanks

    Mark

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Event timing and 2585 errors (2000sp3)

    You can set a flag (boolean variable) to True in the On Exit event of the control, and use the On Timer event of the form to close the form if the variable is True. See ACC2000: Cannot Close Form from Control's OnExit Property.

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Posts
    369
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Event timing and 2585 errors (2000sp3)

    Thanks Hans,

    I'm surprised that this KB article didn't turn up in all my seaching before posting - maybe because there's no reference to Access's own error number for this problem. I'd read references to using the timer function, but didn't twig how to do it.

    Unfortunately, my problem is not solved.

    The last line of my onexit code opens a dummy form who's sole function is to store some values, close the main form, and then reopen it with the stored initialisation parameters. This process works fine from button click events on the main form, but obviously not from enter, exit or focus events. Using the timer workaround, unfortunately, doesn't work, as nothing seems to happen whilst code is running in the dummy form (which is opened in normal view, but the way, not dialog or similar). If I put some pauses into the dummy code, then the main form just waits till the dummy form has finished running and then closes (and thus doesn't reopen), and if I keep the dummy form running until the main form has closed, I enter an infinite loop.

    I've tried moving the code in the dummy form from the form_load to the onenter event of the only control on the form (accepting I would later run into problems with closing the dummy form, but just to see what happened), but it didn't help: the main form still won't close until all code execution has stopped. I even tried to replace the dummy form with a subroutine in a module, in case there was some form related oddness, adding some wait loops to allow the main form to close, but this didn't work either.

    Thanks again

    Mark

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Event timing and 2585 errors (2000sp3)

    I can't say I really understand what you are doing, and why.
    - Why can't you put the code to store the values in the code behind the main form itself?
    - Why do you need to close and reopen the main form? Won't a requery do what you want?
    - Why do you need the On Exit? I almost never use this event.

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Posts
    369
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Event timing and 2585 errors (2000sp3)

    Essentially the answers to all your questions are that this is a multipurpose form, who's function is changed depending on a number of user inputs through popup custom forms, and the flow of code through all these forms is crucial. It's all terribly messy, and if I had time to do it all again I'd plan a different strategy, but it would mean a complete rewrite, and as there are just the 2 of us using this, and it's lifespan is relatively short, it's not worth it. With all the popup forms, the flow of code can get complicated, and closing and reopening the main form is the only way to "reset" everything.

    In the meantime, I've realised I can pass all these parameters to the timer event. I've also realised that it could be the answer to my sendkeys problem, where the sent key was ignored if code execution passed back to a routine other than that which sent the key, which was a pain. I'd still like to understand why that happened, but, as I've said, time is short.

    Is this behaviour (the 2585 error) the same in Office 2003? I could upgrade if I wanted to, but I'm always rather wary with Access that things are likely to break.

    Happy New Year and thanks for pointing me in the right direction once again

    Mark

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Event timing and 2585 errors (2000sp3)

    I don't have Access 2003, so I can't tell you if it behaves the same. The error is not mentioned in the Knowledge Base, but that is not conclusive, since it is still far from complete for the Office 2003 applications.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •