Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to hide pop-up calendar when loses focus 1

Status
Not open for further replies.

BabyPowder2u

Programmer
May 4, 2005
87
US
I am using pop-up calendars on multiple cbofields.

My problem is, Once the calendar opens, if the user clicks on another field on the form, the calendar remains open. I would like it to close.

I tried placing " ocxCalendar.Visible = False"
in each of :
ocxCalendar_LostFocus()
ocxCalendar_Exit(Cancel As Integer)

but in both locations:

I get the error "You can't hide a control that has the focus."

Any help is appreciated.
T
 
Close the calendar in the main form's got focus event. Trap for any error that might occur in those case where your form gets the focus, but the calendar isn't open.
 
How would I do that? (what errors if not open, how to tell?)

Thanks,
T
 
I tried this:

Private Sub Form_GotFocus()
ocxCalendar.Visible = False
Set cboOriginator = Nothing
End Sub

The calendar still remained displayed on top of the form, even if I entered data in other fields.

I don't know how to go about "close the calendar" you recommend.

Thanks,
T
 
How are ya BabyPowder2u . . . .

Your gonna find the forms Lost Event doesn't work like you expect . . . No offense [blue]markgrizzle[/blue], good idea though . . .

So try this:

In a [blue]module[/blue] in the [blue]modules window[/blue], copy/paste the following code:
Code:
[blue]Function IsOpenFrm(frmName As String) As Boolean
   Dim cp As CurrentProject, Frms As Object
   
   Set cp = CurrentProject()
   Set Frms = cp.AllForms
   
   If Frms.Item(frmName).IsLoaded Then
      If Forms(frmName).CurrentView > 0 Then IsOpenFrm = True
   End If
   
   Set Frms = Nothing
   Set cp = Nothing

End Function[/blue]
Next, in the [blue]OnActivate[/blue] event of the form with the [blue]cbofields[/blue], copy/paste the following (you substitute proper names in [purple]purple[/purple]):
Code:
[blue]   Dim PopupFormName As String
   
   PopupFormName = "[purple][b]YourPopupFormName[/b][/purple]"
   
   If IsOpenFrm(PopupFormName) Then
      DoCmd.Close acForm, PopupFormName, acSaveNo
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Ok, I can try that. Just one question. I am using the calendar control 10.0, which is what is popping up... what will I use as "YourPopupFormName"?
 
BabyPowder2u . . . . .

I read a little fast. Sorry about that . . .

In the [blue]OnActivate[/blue] event of the form with the cbofields, copy/paste the following (you substitute proper names in [purple]purple[/purple]):
Code:
[blue]   If Me![purple][b]CalendarControlName[/b][/purple].Visible Then Not Me![purple][b]CalendarControlName[/b][/purple].Visible[/blue]

Calvin.gif
See Ya! . . . . . .
 
BabyPowder2u . . . . .

Scratch the above! I need to take a break!

Calvin.gif
See Ya! . . . . . .
 
I understand AceMan1,

I did try the above, it wouldn't take the "Not Me!.." so I tried setting .visible = false. That didn't solve the problem either.

Still looking :)
 
BabyPowder2u . . . . .

This is gonna be a little tricky. You have to consider what happens if the [blue]calendar has the focus and the user clicks a control (or the same control) that normally opens the calendar!.[/blue]

There's a [purple]focus/visible property conflict[/purple] here that has to be resolved.

Trying to resolve now. Promise I'll get back to ya.

In the meantime, those controls that make the calendar visible, make sure they set the focus to the calendar as well:
Code:
[blue]   Me!CalendarControlName.Visible = True
   Me!CalendarControlName.SetFocus[/blue]
Also remove/delete any existing code to manipulate this issue (start fresh).



Calvin.gif
See Ya! . . . . . .
 

each cboDateX field has this code: (and has all along)

ocxCalendar.Visible = True
ocxCalendar.SetFocus

removed the form_activate sub

the form_gotfocus() had been commented out, but removed it
ocxCalendar_lostfocus() had been commented out, but removed it
ocxCalendar_exit() had been commented out, but removed it


That's all I had trying to re-set it. So, everything is cleaned up..... ready to try next step.

Thanks,
T
 
OK BabyPowder2u . . . . .

To explain a little: The problem is, [purple]you can't hide a control while it has the focus[/purple]. Also, you can't simply set focus to another control to alleviate the problem . . . particularly with code running in the focus events. The event has to finish or no go.

The problem is resolved as follows:
[ol][li] The calendar [blue]LostFocus[/blue] event sets a [blue]Timer Interval[/blue] of 50 milliseconds (more than sufficient time for a very slow machine).[/li]
[li]While the timer is running, [blue]enough time passes[/blue] for the Calendar [blue]LostFocus[/blue] event to complete and the [blue]current focus[/blue] to set itself to the selected control.[/li]
[li]When the [blue]Timer Interval[/blue] runs out, the [purple]Timer[/purple] event takes control. Its here the decision is made (according to the previous control that had the focus) wether to hide the calendar. If you click a control that opens the calendar it remains open, otherwise not. To complete the code, the [blue]Timer[/blue] event sets the [blue]Timer Interval[/blue] to 0.[/li]
[li]Mission Accomplished![/li][/ol]
So . . . in the Calendar [blue]LostFocus[/blue] event, copy/paste the following:
Code:
[blue]   Me.TimerInterval = 50[/blue]
Next, in the Forms [blue]OnTimer[/blue] event, copy paste the following ([blue]you![/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]   Dim prevName As String
   
   prevName = Screen.PreviousControl.Name
   
   If prevName = "[purple][b]CalendarControlName[/b][/purple]" Then
      Me!purple][b]CalendarControlName[/b][/purple].Visible = False
   End If
   Me.TimerInterval = 0[/blue]
[purple]Thats it . . . give it a whirl & letme know . . .[/purple]


Calvin.gif
See Ya! . . . . . .
 
Well, I added the LostFocus event as follows:

Private Sub ocxCalendar_LostFocus()
Me.TimerInterval = 50
End Sub

the ontimer event as follows:

Private Sub Form_Timer()
Dim prevName As String
prevName = Screen.PreviousControl.Name
If prevName = ocxCalendar Then 'both w/wo "" around name
Me!ocxCalendar.Visible.Visible = False
End If
Me.TimerInterval = 0
End Sub

Neither way cleared the calendar from view... it does for some reason clear the "frame border" from around the calendar.

Any other ideas?
T
 
AceMan,

When you said "Scratch the above! I need to take a break!" and "Also remove/delete any existing code to manipulate this issue (start fresh)."

Did you mean for me to have/not have the module
"Function IsOpenFrm(frmName As String) As Boolean..."

I do not have it, & didn't try it because of the "Scratch.." post. (and honestly I'm not sure what it does)

Thanks,
T
 
BabyPowder2u . . . . .

Sorry about the typo's.

Delete the old [blue]Timer[/blue] Routine then copy/paste the new code below:
Code:
[blue]Private Sub Form_Timer()
   Dim prevName As String
   
   prevName = Screen.PreviousControl.Name
   
   If prevName = "ocxCalendar" Then
      Me!ocxCalendar.Visible = False
   End If
   
   Me.TimerInterval = 0

End Sub[/blue]
BabyPowder2u said:
[blue]Did you mean for me to have/not have the module
"Function IsOpenFrm(frmName As String) As Boolean..."[/blue]
In your post origination, I thought you were talking about a popup form. [blue]IsOpenFrm[/blue] is a function that [purple]tells you if a form is already open[/purple]. There are a great many times when this needs to be known. So you may want to keep it!

Calvin.gif
See Ya! . . . . . .
 
Thank you AceMan,

That took care of it.. I had already taken out the .visible.visible that appeared in my code, & didn't see any difference between what I had & what you posted.... (and thought I re-tested both ways)

No matter, that fixed it.

Thanks,
T
 
BabyPowder2u . . . . .

You don't have to post back, but you also forgot or took out the double quotes in:
Code:
[blue]If prevName = [purple][b]"[/b][/purple]ocxCalendar[purple][b]"[/b][/purple] Then[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top