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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting focus from one (popup) form to another form

Status
Not open for further replies.

Aubs010

Technical User
Apr 4, 2003
306
GB
I have a form (frm_Inspection) with a sub form (frm_Inspection_Sub).

on the sub form, I have a couple of fields, one being named "Insp_SampleConditionScore_ID_Item".

When that field gets the focus, I have set it so that another form (frm_PopupForm_Examples) opens automaticaly, with examples of entries. The popup form is set as "popup" so it stays on top of all other forms, but not "Modal" so the focus can be moved to the other forms.

The problem I have, is that I need it so that when the popup form opens, it sends the focus back to the calling field, while leaving itself in position (i.e. not closing).


I think this may be a problem because:

SUB - Get Focus
SUB - Opens popup
POP - Popup Form opens
POP - returns focus
SUB - Get Focus
SUB - Opens popup
POP - Popup Form opens

Causing a loop...

Although if I use the following code:
Code:
Private Sub Form_Load()
    [COLOR=green]'check if the form should open. (Works fine)[/color]
    If Me.ONorOFF_Check = True Then DoCmd.Close
    Forms![COLOR=red]frm_Inspection_Sub[/color]![COLOR=blue]Insp_SampleConditionScore_ID_Item[/color].SetFocus
End Sub
It doesn't switch the focus...

Any help greatly appreciated.

Aubs
 
Ello,

Put a hidden field of your form and populate it when you first hit the onfocus event, then whenever you hit that event again and check the hidden field you can just ignore the pop up code.

Hope that makes sense.

Simon

----------------------------------------
I was once asked if I was ignorant or just apathetic. I said, "I don't know, and I don't care."
----------------------------------------
 
hmmm, not entirely!!

I think you mean when the field in question gets the focus (OnGotFocus):

Populate hidden field.
Popup box appears.
Focus is taken by Popup.

That's the problem... returning the focus to the field that carried out the OnGotFocus event...

From what I can gather, the field doesn't actually loose the focus, it's just the form that looses the focus...?!

Thanks again!

Aubs
 
Ello,

what I mean is:

OnLoad - Main form
Code:
Me.txtHidden = 0

GotFocus - Main form textbox
Code:
If Me.txtHidden = 0 Then
    'Code to open PopUP
    Me.txtHidden = 1
End If

OnOpen - Popup
Code:
Forms!MainForm.TextBox.SetFocus

OnClose - popup
Code:
Me.txtHidden = 0

That should mean you don't get stuck in the loop, I haven't actually tested any of this though.

Sim

----------------------------------------
I was once asked if I was ignorant or just apathetic. I said, "I don't know, and I don't care."
----------------------------------------
 
I see what you mean... Right, Thanks for your help, I've got to leave the office now, but will have a look back tomorrow.

Thanks again,



Aubs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top