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

Move Focus to Mainform

Status
Not open for further replies.

FredaH302

MIS
Dec 15, 2006
22
US
I have a delete button that selects all related records in a subform and deletes them. This works fine.

I then want to move back to the main form and delete the main record.

I have tried:
Forms![Main Form].[Field].setfocus
Me.Parent!Field.SetFocus

The commands are ignored. What is the correct syntax??
 
You should set the focus to the form before:
Me.Parent.SetFocus
Me.Parent!Field.SetFocus

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This is the darndest thing. It flat out will not work.

Here is my actual code:
Forms![frm_housing].Form![frm_FeatureS].SetFocus

DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdDeleteRecord

Me.Parent.SetFocus
Me.Parent!Facility.SetFocus

The subrecords are deleted fine, but the focus will not move back to the main form. I have this code attached to a command button and the subform is on a tab control - not that any of that should matter? What am I doing wrong?
 
And what about this ?
Forms![frm_housing].Form![frm_FeatureS].SetFocus
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdDeleteRecord
Forms![frm_housing].Form.SetFocus
Forms![frm_housing]!Facility.SetFocus

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Actually, that was one of the first things I tried. Just for the heck of it, I tried it again with no luck. The focus will not budge from the subform. There is really nothing special about the form.

 
With patience comes reward. Specific records on the subform had no related records, which caused the delete command to bomb. The default error description was turned off so it did not return a reason. This stopped the remainder of the code from processing.

Once I accounted for the possibility of an empty related recordset, I could get the focus to move to the main form.

Thanks for your input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top