Question:
VBA Access 2000 hide a control on lost focus or something similar?
philip32189
2008-07-02 14:31:04 UTC
I am working on a form which has approx 40 controls and a great large mass of code. I put in a feature to emulate datetimepicker controls (dropdown boxes with a built in calandar) by using mscal.ocx. These calandars stay hidden until the user clicks on the associated dropdownbox and are rehidden when the user clicks on the calendar control. What I need is if the user clicks on anything other than the calendar while the calendar is not hidden, the calendar should become hidden. I have tried using the lostfocus method. That didn't work because that stupid method temporarily brings focus back to the control which lost focus and one cannot hide a control which has focus. Furthermore this method cannot bring focus to another control because doing so would result in an infinite looping of control focusings. I have also tried hiding all 3 of my kludgy date calandar comboboxes by creating an onclick procedure for all other 37 controls on the form without avail. Any ideas???
Three answers:
ArmchairPilot
2008-07-03 11:03:36 UTC
You could try using the form's timer:



For each control's GotFocus event, add



Private Sub Control_GotFocus()

   TimerInterval = 30

End Sub



And for the form's timer event



Private Sub Form_Timer()

   TimerInterval = 0

   DatePicker.Visible = False

End Sub



Every time a control is clicked on (gets the focus), the time event handler fires 30 msec later, apparently almost instantaneously.
snorkyller
2008-07-03 13:34:36 UTC
I had exactly the same problem about 5 years ago but I don't still have the code.



There's the sendkey command that allow to send a key, it's as if you press a key. So, if you send the TAB key, you send the focus to an another control. Precisely, to the next control on your tab order (I mean: which control will got the focus when you press TAB). Remember that you can configure the tab order in the controls properties within Access.



Use sendkey within the lostfocus method of your calendar. I think it may works.



There's 2 values you must give with the sendkey command when you call it. The first is which key you want to send. I don't remember the second, but I think it should be "false".



If I'm not wrong, I think that the lostfocus method is the first to be call. It is call before the control lost the focus. Then the focus is send to the other control and then, the gotfocus method of this control is called.



Hope this will help
Eziblogger
2008-07-06 11:08:58 UTC
Have you tried using the Enter event instead?



---

Private Sub controlname_Enter()

ocxCal.Value = Date

ocxCal.Visible = False

End Sub

---



When the user clicks on any other control, the enter event for the control the user clicks in is triggered. The value for the calendar is reset and then the calendar is hidden. You'll need to use this in the enter event for all your other 37 controls.



HTH


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...