setting focus in a subform

UsingTime
NewLounger
Posts: 16
Joined: 29 Apr 2010, 01:38

setting focus in a subform

Post by UsingTime »

When tabbing out of a text box "txtWeight" on a main form "frmOrdersMain", I would like to have the focus set to combo box "ItemID" on a subform "frmOrderDetails".

I was thinking of putting the code as an "OnExit" event. Would that be right, and what would that code look like?

Any help is appreciated!

Mark L
3StarLounger
Posts: 331
Joined: 11 Feb 2010, 03:55
Location: Land O Lakes, FL

Re: setting focus in a subform

Post by Mark L »

If you only want to do this if you tab-out of txtWeight, I'd create a transparent command button, setting its tabIndex property to be the next control after txtWeight. Then in the OnEnter event of this new control, I'd have this code:

Code: Select all

frmOrderDetails.setfocus
frmOrderDetails.form.ItemID
This assumes that the subform control name is frmOrderDetails.
Mark Liquorman
Land O Lakes, FL
see my website http://www.liquorman.net for Access Tips and Tricks, and for my Liquorman Utilities.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: setting focus in a subform

Post by HansV »

I think Mark forgot a SetFocus and meant to post

frmOrderDetails.SetFocus
frmOrderDetails.Form.ItemID.SetFocus

As Mark mentioned, you should use the name of the subform as a control on the main form. This is not necessarily the same as the name of the subform in the database window.
Best wishes,
Hans