Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you close an Access97 form from within an event of a control?

Status
Not open for further replies.

Sorrells

Programmer
Dec 28, 2000
92
US
I keep getting an error when I attempt to close a form from within the LostFocus event of one of it's controls. I am beginning to think it cannot be done and would appreciate a confirmation of this.
I can close the form from a command button on it but not within a control. I sure would like to however.
The context is a form to enter data record for a problem database. One of the fields to complete is named lognumber and must be a unique number (it is indexed). I perform a dLookup on the table to determine if the lognumber already exists. If it does I send a message to the user stating that they are attempting to enter a duplicate number and give them a CANCEL or OK choice.
The CANCEL sends them back to the control to rekey if that is the problem.
The OK button opens code where I change the lognumber, write the record, delete the record, then I want to close the form. It seems that no matter how I code it, if a CLOSE is within the event procedure I get the error.
I have tried a function in a module but still get the error, I guess because the procedure in the control event still has not completed. I have tried to goto a control OnClick event to close the form but still no luck.
Any advice as to how to deal with this will be appreciated.
Regards,
Sorrells


 
So after they enter the last bit of data in the last textbox on the form you would like it to close. right?



DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
 
Doug,

No, it is more complex than that. Rather than go into detail, let me tell you that a solution was suggested in another forum, that I use the AfterUpdate event rather than LostFocus for the textbox. This does work however it will take some time to resolve other issues that had lead me to the LostFocus event in the first place.
I am still of the opinion that the LostFocus event of a form control will not support the closing of the form at all.
Thanks for your response! Sorrells :)
 
I'm inclined to agree. While the LostFocus is executing, you still have pending Enter and GotFocus events for another control. The pending events may be what prevents the Close. What kind of error are you getting, BTW?

Instead of closing in LostFocus, you could try setting TimerInterval to 1 ms. In the Timer event, close the form. That might work, and would let you continue using LostFocus to resolve the "other issues".
 
The error was 2585 (this action can't be carried out when processing a form). On a suggestion from Jimmy the Greek I moved the code to AfterUpdate but now I am curious since I know nothing about the timer event.
I just looked at the help for timer and feel no less enlightened. We have never used this event here. I wish MS would provide more context to their help descriptions.
Rather than take up your time, I'll leave this as is, but I will be more aware of this Timer event to see if I can take advantage of it in the future.
Thanks,

Sorrells
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top