Moving from command button in main form to subform (1 Viewer)

Toolman

Access Newbie
Local time
Today, 19:24
Joined
Jul 25, 2009
Messages
28
Hello,

I have a PatientF, with a SubFormF. PatientF has several fields to enter info about the patient. The last item in PatientF is a command button (OpenParentbtn). This button opens the ParentF to enter the parent information. When ParentF closes. OpenParentbtn has focus.

From this point, how do I move the focus to the SubFormF? I have tried numerous combinations but can't get the focus to move.

Your help would be appreciated.

Thanks,
Don
 

RuralGuy

AWF VIP
Local time
Today, 17:24
Joined
Jul 2, 2005
Messages
13,826
Moving focus from a MainForm to a SubForm is a two step process.
Me.SubFormControl.SetFocus
Me.SubFormControl.FORM.ControlOnSubForm.SetFocus
 

Toolman

Access Newbie
Local time
Today, 19:24
Joined
Jul 25, 2009
Messages
28
RuralGuy,
Thank you. But I don't know where to use this code. Sorry, I'm very new.

I've tried using this in the ParentF's OnClose event, but its my guess it doesn't work because PatientF doesn't yet have focus.

Could you give me an idea on where to use this code? Many thanks,
Don
 

RuralGuy

AWF VIP
Local time
Today, 17:24
Joined
Jul 2, 2005
Messages
13,826
What do you have behind the OpenParentbtn button?
 

Steve R.

Retired
Local time
Today, 19:24
Joined
Jul 5, 2006
Messages
4,617
RuralGuy,
Thank you. But I don't know where to use this code. Sorry, I'm very new.

I've tried using this in the ParentF's OnClose event, but its my guess it doesn't work because PatientF doesn't yet have focus.
It would not be placed in the ParentF's OnClose event. Depending on what you want to do, it would be placed either on the PatientF's Load Event or Current Event. I assume that you want it under the Load Event. Then use the solution provided by RuralGuy.

Having said that, what you are proposing seems to bypass entering your data on the main form itself. Subforms tend to be used to display information in datasheet view, not for data entry. With that in mind, there is seldom a time for moving the focus to a particular field in the subform. I usually use the double click event on the field in the subform when changes are needed to the data in the subform.
 

Toolman

Access Newbie
Local time
Today, 19:24
Joined
Jul 25, 2009
Messages
28
This has all stemmed fom trying to find a solution to a many-to-many problem.
I undestand the need for a juction table and how to set it up. But what I struggled with was an easy method to populate the junction table.
I found an example and modified it slightly.
I have children that are on program for speech therapy. But I can have 2 or more children on program at the same time. So I can have 3 kids with the same mother and vice versa. Plus, there may be other adults that must be kept in the loop.
So I have PatientF, where I enter pertinent data about the child. The command button opens the ParentF where I enter the parent's names and relationship (mother, step father, guardian, etc). Upon closing the ParentF I need to move to the subform (junction table) so I can create the relationship between childand adult.
By making the selections in the subform, I automatically populate the junction table.

Everything works, except me making it as easy as possible for the users to make their way thru the form/subfom. I'm going to try your suggestion f placing your code in the Current event to see if that works.

Thanks again for your help.
Don
 

Steve R.

Retired
Local time
Today, 19:24
Joined
Jul 5, 2006
Messages
4,617
Upon closing the ParentF I need to move to the subform (junction table) so I can create the relationship between childand adult.
I have something loosely similar but it is done from the main form using combo boxes to establish the relationship link. What you would do is have a combo box that lists all the possible adults that would be associated with that particular child. The subform (as a query), would then display (datasheet view) all the adults associated with that particular child.

RuralGuy is very helpful. I hope that you will answer his question. He may have better insight than I.
 

Toolman

Access Newbie
Local time
Today, 19:24
Joined
Jul 25, 2009
Messages
28
Sorry RuralGuy,
No disrespect intended. I simply don't know what you mean by "behind the OpenParentbtn button".

it opens the ParentF form. I used the on click event to open the form to acAddNew.

Beyond that I'm not sure what you mean?

Don
 

RuralGuy

AWF VIP
Local time
Today, 17:24
Joined
Jul 2, 2005
Messages
13,826
In design view of the form, right click on the button and select properties. Select the event tab and click the "..." button nect to the Click event and let us know what you have.
 

RuralGuy

AWF VIP
Local time
Today, 17:24
Joined
Jul 2, 2005
Messages
13,826
Sorry but I have to go to a meeting now. I will check back in a few hours.
 

Toolman

Access Newbie
Local time
Today, 19:24
Joined
Jul 25, 2009
Messages
28
One line of code:

DoCmd.OpenForm "ParentF", , , , acFormAdd

Don
 

RuralGuy

AWF VIP
Local time
Today, 17:24
Joined
Jul 2, 2005
Messages
13,826
Change it to:
DoCmd.OpenForm "ParentF", , , , acFormAdd, acDialog
Me.SubFormControl.SetFocus
Me.SubFormControl.FORM.ControlOnSubForm.SetFocus

...using *your* SubFormControlName and ControlName of course.
 

Toolman

Access Newbie
Local time
Today, 19:24
Joined
Jul 25, 2009
Messages
28
Thanks very much RuralGuy! It works great.

I really appreciate the help.

Don
 

Users who are viewing this thread

Top Bottom