By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,476 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,476 IT Pros & Developers. It's quick & easy.

How do I hide a control when I click on anything else

P: 13
I created a calendar pop up on MouseDown event. The calendar looses focus (Calendar3.Visible = False) only when I dblClick on a date on the calendar, at which point the date value is transferred to the field value. How do I make the calendar invisible when I click on anything else on the form. for example, If someone clicks on a field by accident, they can't get rid of the pop-up calendar until they choose a date. below is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Calendar3_dblClick()
  2. 'Code for when clicking on the calendar
  3.  
  4. Originator.Value = Calendar3.Value
  5. Originator.SetFocus
  6. Calendar3.Visible = False
  7. Set Originator = Nothing
  8.  
  9. End Sub
  10. ------------
  11. Private Sub DateScheduled_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  12.  
  13. Set Originator = DateScheduled
  14. Calendar3.Visible = True
  15. Calendar3.SetFocus
  16.  
  17. If Not IsNull(DateScheduled) Then
  18.     Calendar3.Value = DateScheduled.Value
  19. Else
  20.     Calendar3.Value = Date
  21. End If
  22. End Sub
thank you!!!
Jan 20 '12 #1
Share this Question
Share on Google+
3 Replies


Expert Mod 2.5K+
P: 2,545
If your calendar form is opened as a modal form - one which will always be on top of all others until it is closed - you won't be able to hide or close it unless you include a button for that purpose on the form itself. Once a modal form is opened/unhidden no other form or control can gain focus until the modal form is closed.

You may be better off associating the pop-up calendar with the DateScheduled control's double-click event instead of its mousedown event. You will have to advise users to double-click to open your calendar, but this is the normal way of working for other applications which use such calendars.

From Access 2007 on textbox controls have a built-in date picker which does away with the need for complex calendar management, so you must be using A2003 or earlier at present.

-Stewart
Jan 21 '12 #2

P: 13
I think the Calendar is a control; not a form...so i was not able to add a button to close the control...I was also not able to make the control visible on a dblClick event. Not sure why it didnt work, possible because it was a control?

any other suggestions? I am using Access 2003. I'm a beginner to Access VBA so i am trying to keep up. Thanks for your help!!
Jan 23 '12 #3

Expert Mod 2.5K+
P: 2,545
If you can make the control visible on the Mouse Down event, there is no reason at all why you cannot switch it to the Double Click event instead. If you change the heading for your DateScheduled_MouseDown Sub as follows this should transfer the event to the Double Click one instead:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DateScheduled_DblClick(Cancel as Integer)
Just make sure after you make this change that the event properties of the DateScheduled control now show [Event Procedure] in the On Dbl Click event property of the control instead of the On Mouse Down property.

-Stewart
Jan 23 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.