Close a form by clicking anywhere on it

A

Adam Thwaites

Hi, I have the following code to close a form by clicking anywhere on it:

Private Sub Form_Click()
Forms![frm_Main].SetFocus
DoCmd.Close acForm, "frm_DueBack"
End Sub

I also tried this for detail click but it didn't work when I clicked on the
lables on the form. How can I get the above code to work for if you click on
a lable's aswell, without having individual code for each label?

Thanks

--
Adam Thwaites
Access Database Designer
adam.*spamless*[email protected]
Manchester, UK
(I have no access to other sites apart from microsoft.com so posting
external links is no use to me)
 
R

Rick Brandt

Adam said:
Hi, I have the following code to close a form by clicking anywhere on
it:

Private Sub Form_Click()
Forms![frm_Main].SetFocus
DoCmd.Close acForm, "frm_DueBack"
End Sub

I also tried this for detail click but it didn't work when I clicked
on the lables on the form. How can I get the above code to work for
if you click on a lable's aswell, without having individual code for
each label?

Thanks

The click event of a form section only runs when you click on an exposed
area of the section's background. Try placing a CommandButton over the
entire form area and making it transparent. Then use the button's Click
event.
 
A

Adam Thwaites

Isn't there a 'proper' way to do it like the *Key Preview* option for key
presses?
--
Adam Thwaites
Access Database Designer
adam.*spamless*[email protected]
Manchester, UK
(I have no access to other sites apart from microsoft.com so posting
external links is no use to me)


Rick Brandt said:
Adam said:
Hi, I have the following code to close a form by clicking anywhere on
it:

Private Sub Form_Click()
Forms![frm_Main].SetFocus
DoCmd.Close acForm, "frm_DueBack"
End Sub

I also tried this for detail click but it didn't work when I clicked
on the lables on the form. How can I get the above code to work for
if you click on a lable's aswell, without having individual code for
each label?

Thanks

The click event of a form section only runs when you click on an exposed
area of the section's background. Try placing a CommandButton over the
entire form area and making it transparent. Then use the button's Click
event.
 
R

Rick Brandt

Adam said:
Isn't there a 'proper' way to do it like the *Key Preview* option for
key presses?

I don't believe there is any Windows convention for closing a form by clicking
anywhere on it so a "proper" way to implement that is a bit of an oxymoron.
 

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