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

When Got/Lost Focus Event Occur on Subform 1

Status
Not open for further replies.

gallas

Technical User
Feb 5, 2002
55
GB
I have been having difficulty with Got / Lost Focus events on a Subfom. I have a ComboBox control on a Subform with a DblClick event that calls another form to add records to the table which the ComboBox refers to. This works fine.

However, I want to requery the control on the subform when closing the popped up form. Putting the code in the close event is inconvienient because this form could be opened when the subform is not open thus generating an error. My approach was to attach the requery code to the GotFocus event on the subform control. But for some reason the control does not seem to lose focus when opening the other form. (I put a msg box trap on the got focus event to see when exactly it occured) I have tried continuous form and datasheet views and also putting the code on the enter and click events - but no Joy. :-(

I have this exact code working elsewhere but only from a main form, when the popped up form is closed the focus returns to the control on the main form and requeries.

Can anyone help with this please? Maybe there is a different approach?

Tks in advance.
 
I was trying to do something similar with the not in list event.

Possibly this thread will help you.

thread702-565103 Luck
 
Thanks for the (Long!) thread. The approach is a bit complicated and not really what I am trying to achieve. Actually all I am doing is leaving the subform to enter data into the popped up form and need an event that triggers when I re-enter the subform to re-query the original control. Such an event doesn't seem to exist because the control focus is never lost.

I suppose a slightly untidy way would be to make a copy of the pop up form that is only opened from this subform. I can then put the requery code on the forms close event. (This works okay). So unless anyone else has some input that seems to be the way to go.

Thanks again. G :)
 
What is your exact[/b] code to open the popup form from the subform?

You may need to DoCmd.OpenForm in dialog mode and requery the subform by Me.Requery immediately after that line.

Opening a form in dialog mode pauses code execution until the dialog is closed.

Good luck



[pipe]
Daniel Vlas
Systems Consultant

 
Thanks Daniel, Its a simple piece of code attached to the dblclk event on the subform combo control:

Private Sub UnitType_DblClick(Cancel As Integer)
On Error GoTo Err_UnitType_DblClick

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "UnitTypesForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria

There is no more code just error handling. I may have said the wrong thing by saying popup. The form opens with pop up and modal set to NO. And with the allow properties to allow everything. Also it is not set to dialog style.

If this form is opened from a combo control on the main form as soon as it is closed the control on the main form seems to get the Got Focus event and runs the requery. But when opened from the control on the subform it seems that the subform control keeps focus, so a got focus event doesn't occur?? If I click elsewhere and the re-click the control the Got Focus event occurs.

Your suggestions appreciated. G. [neutral]
 
Yr code Didn't work as I expected it to. I understand that the Me.Requery will now be processed when UnitTypesForm closes, but it doesn't seem to requery the control on the subform.

However, what does happen is that the user is returned to the first field in the subform. Therefore moving to the original control gives a Got Focus event and bingo we have an event to work with! Maybe that's what you meant to happen? Anyway - helpful post means stars. Tks again.
[thumbsup]
 
Oh! This works and returns the cursor to the original control:

DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
Me!UnitType.Requery

Where "UnitType" is the name of the combo-box control.

Tks, again. (-:
 
If you're running the code from the main form:

DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
Me.SubformName.Form![ControlName].Requery

If you're running the code from the subform:

DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
Me![ControlName].Requery

Thanx for the star.




[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top