Screen refresh as Form closes

kirkm

Registered User.
Local time
Today, 13:04
Joined
Oct 30, 2008
Messages
1,257
I have a modal & popup form bound to a table to allow me to choose data from the table.
Sub Form load sets Me.Recordsource to Me.OpenArgs, which is the query passed in.

A double click event for the required field handles the data and ends with code "DoCmd.Close"

Everything works as intended except when Form is closed by the X in top right corner.
Then it takes a second or two for the Form to close and refresh the screen underneath. (This does not happen when the double click event fires, instead of via "X").

Any idea why? Can I avoid that screen refresh delay?
 
Add a private boolean vauable ti the load event of the form.

dim bolClosing as boolean
Private sub form_load()
bolClosing=false
End sub



Before usuing Docmd.Close, set the variable to True

bolClosing=True
Docmd.close



On the close event of the form, chk the variable

Private sub form_close(cancel as integer)
Cancel= not bolClosing
If not bolClosing then
Msgbox "Cannot close at this time"
End if
End sub
 
Hi, I got very strange results when I tried that. My query no longer seemed to work but also
"The expression On Close you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name."

The only way I found to avoid that was to remove Private sub form_close(cancel as integer) after which my query worked again. So I can't test it to see results.
 
Ok sorry i have not tested yet check if the Unload event has Cancel parameter then move the code there.
 
Using the Unload event, the "cannot close" prompt was present all the time and couldn't be avoided. (Unless the DoCmd.Close executed)
 

Users who are viewing this thread

Back
Top Bottom