Full Version: Close Calendar control when focus lost/click elsewhere on main f
UtterAccess Forums > Microsoft® Access > Access Forms
Hello all,
It's me, the resident newby once again...
I have a form that has two fields for entering dates (to and from dates). The date fields are combos, and when the user clicks the combo boxes this opens up a pop-up calendar form (MS Calendar control). To open the calendar, I have the following "on mouse down" for the DateFrom combo:
Private Sub DateFrom_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
CalendarFrom.Visible = True
If Not IsNull(DateFrom) Then
CalendarFrom.Value = DateFrom.Value
End If
End Sub
When a date is selected from the calendar, no problem, the calendar closes and transfers the date to the combo. The problem is that if a user clicks the date field/combo and the calendar pops-up, and the user changes their mind and doesn't want to enter a date or use the calendar, the calendar remains open... Even when clicking somewhere else on the main form. crazy.gif
How do I get the pop-up calendar to close if the user clicks off of the calendar, such as somewhere else on the form (and without putting a date in the date field/combo in the process)?
I tried using DoCmd.Close on Lost Focus, but that doesn't have any affect, but seems to change the Visible property to Yes (when I need it to be No so the calendar is hidden until called upon).
Any help would be greatly appreciated!
The easiest way to do this is to place the Calendar control on another form
with the form's modal and popup properties set to true. That way the form has
to be closed before focus can be transfered back to the other form.
That's good info Ace, thanks. I kind of wondered about that as an option before back when I was first designing the form. I think I found a solution that is working out to be pretty close to what I wanted:
put the following on my two (From/To) calendar controls - -
Private Sub CalendarFrom_Exit(Cancel As Integer)
DateFrom.Value = Null
CalendarFrom.Visible = False
End Sub
Now, when you click in the DateFrom combo, the calendar control opens... if you click in any other field on the form, the calendar control closes, and leaves the DateFrom blank (but leaves focus/cursor in the combo). So that is working much better.
Does anyone know how I can improve that a little more?
I guess my goal is either:
1) Using the solution above, but have the focus in the field you just clicked (to close/cancel the calendar).
2) Using the solution above, but be able to click anywhere (i.e. open space) on the form to have the above code take affect.
>I put the following on my two (From/To) calendar controls - -
That happens if you actually try to pick a date from the calendar control?
Well, quite simply, it doesn't work if I try to pick a date - - Ooops, pretty funny... I know, the one thing I didn't check (not sure how that slipped by my brain!), I discovered this early this morning at work - - so much for my fix! I ended up just setting everything back to ground zero.
> Well, quite simply, it doesn't work if I try to pick a date
eah, I know frown.gif
Go with the seperate, modal form for the calendar popup and move on to the
next problem.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.