Closing a subform

T

Tim

Hello,

I have a form with a command button which open a smaller
form. The second (smaller) form has a close button on it
which of course closes the form. I would also like the
second form to close if the user clicks anywhere outside
the smaller form. So, if the user clicks anywhere in the
first (larger) form the smaller form closes. I know that
the command

Docmd.Close acForm, "smaller form",acSaveYes

will do it if I place this command in the onclick event of
a field on the larger form. However, I don't want to
place this code in every field of the larger form.

Where do "on deactivate" or "on lost focus" or any other
event come into play? I tried placing a Docmd.Close
command in these events for the smaller form, but it
didn't work. I also tried to place the above command in
the "on got focus" and "on active" events of the larger
form.

Is there no way to do this?

Thanks in advance

Tim
 
6

'69 Camaro

Hi, Tim.

Place your code to close the smaller form inside the larger form's Detail
section's On Click( ) event.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
V

Van T. Dinh

It sounds like you want to close the small Form as soon as it is
de-activated or loses Focus. In the case you can use the
frmSmall_Deactivate Event (or LostFocus Event) to close itself with the
statement:

DoCmd.Close acForm, Me.Name, acSaveNo

BTW, I use the acSaveNo above but note that you used acSaveYes. This
argument only save / don't save the *design* changes of the Form, not the
data. Data is automatically saved in bound Form (unless you have code
commanding the Form not to save data upon closing).

HTH
Van T. Dinh
MVP (Access)
 
T

Tim

I tried using the small form LostFocus and Deavtivate
events before I posted this problem and could not get
either one to work. I just tried it again and still could
not get it to work.

By placing the close in the big form detail on-click event
and in each feild on-click event the small form will
close. I have it working this way, but it seems like the
small form events should do it. I'm I missing something?

Phil
 
V

Van T. Dinh

It is possible that the (small) Form does lose the Focus if it doesn't have
it.

Try the Form_Activate Event of the (big) Form.
 

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

Top