Can you close an Access97 form from within an event of a control?
Can you close an Access97 form from within an event of a control?
(OP)
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
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
RE: Can you close an Access97 form from within an event of a control?
DougP, MCP
dposton@universal1.com
Ask me how Bar-codes can help you be more productive.
RE: Can you close an Access97 form from within an event of a control?
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
RE: Can you close an Access97 form from within an event of a control?
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".
RE: Can you close an Access97 form from within an event of a control?
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