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

Move from a control in a subform to a control in the main form 2

Status
Not open for further replies.

CVesta81

Technical User
May 17, 2012
23
CA
Hello,

I have a main form with a subform in it. The main form's name is frm1ASalesOrders and the subform's name is frmA3SalesOrderDetail. I am trying to program a Lost Focus event so that when the last control in the subform loses its focus, the control RCH_CheckDate gets the focus in the main form. I have tried working on this for about an hour and have yet to come up with a solution. What is the best way to accomplish this task?

Thanks,
Chris
 
Is it possible to help me with the code? I'm not familiar with setting focus to a parent. This is the code I tried:

Code:
    Forms!frmA1SalesOrders.SetFocus
    Forms!frmA1SalesOrders!RCH_CheckDate.SetFocus

What am I doing wrong?
 
If RCH_CheckDate is the Control that is to receive Focus:

Me.Parent.RCH_CheckDate.SetFocus

Linq ;0)>

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
IIRC you need to set the focus first to a form or subform and then another statement to set the focus to a control on that form.

This worked for me from a [Description] control on the subform:
Code:
Private Sub Description_LostFocus()
    Me.Parent.SetFocus
    Me.Parent.RCH_CheckDate.SetFocus
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Your memory is half-right, Duane. When moving from a Main Form to a Control on a Subform you have to first set Focus on the Subform Control, then on the target Control, but the reverse is not true!

Code:
Me.Parent.RCH_CheckDate.SetFocus

works just fine in 2007, without setting Focus to the Main Form first.

In point of fact, while you can always set Focus to a Subform Control, you can only set Focus to a Form if there are no Controls on the Form that can receive Focus.

Linq ;0)>

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
OK, so neither of those worked for me for some reason. I am including the code in the LostFocus for the last control in my subform (Private Sub Notes_LostFocus()). I am getting the message, "Run-time error '438': Object doesn't support this property or method." What am I doing wrong? Do I need to include this code on the LostFocus of the subform itself?
 
Basically, Access is saying that RCH_CheckDate is not a Control that Focus can be set to. Is it a Field name, perhaps, rather than the name of the Textbox that is bound to RCH_CheckDate?

In Form Design View, click on the Control to select it and go to Properties - Other and see what's in the Name Property Box.

Linq ;0)>

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Perfect! Missinglinq, you were right! I was referencing the field and not the control. The names were very similar, but not identical. I appreciate everyone's help with this!
 
Glad we could help!

Good luck with your project!

Linq ;0)>

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top