Link to home
Start Free TrialLog in
Avatar of SparkyP
SparkyP

asked on

Go to New record on subform Disabled control

I have a main form "Standards" with a subform (Continuous Form), "NatureofNonConformance" on a tabbed page on the main form. If Non Conformance is selected on the Main form the user is directed to the Subform. Here they enter the details of the non conformance.

I have put the follow code into the On Current event of the subform to prevent users deleting or editing previously entered details ( I cannot disable edits etc on the subform as there are other controls that need to be editable , "ActionCompleteBy")

If Not IsNull(Me!NatureofNC) Then
Me!NatureofNC.Enabled = False
Else
Me!NatureofNC.Enabled = True
End If

I also have a command button on the main form, to enable viewing and editing of enabled controls, which sets focus on the subform.

using:
 Me!NatureofNonConformance.SetFocus


I would like to go to a new record on the subform to enable additional entries, however, when I use
 Me!NatureofNonConformance.SetFocus
DoCmd.GoToRecord , , acNewRec

it takes me to a new record on the main form.
Ideally I would like the command button to take me to the subform on a new record, setting focus on the "NatureofNC" control.

Where am I going wrong?
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Try setting focus to a Control on that subform:

Me!NatureofNonConformance.SetFocus
Me!NatureofNonConformance.Form.SomeControl.SetFocus
Avatar of SparkyP
SparkyP

ASKER

Thanks Scott

That works fine, but takes me to the first record in the subform, rather than a new one. Where would I put the:
DoCmd.GoToRecord , , acNewRec
Not that this has anything to do with your trouble, but you can do away with those If blocks if you're prefer:

Me!NatureofNC.Enabled = Not IsNull(Me!NatureofNC)
but takes me to the first record in the subform, rather than a new one
After the second line ... sorry, thought that was understood :)
Avatar of SparkyP

ASKER

That's what I have being doing, but that takes me to anew record on the main form

 Me!NatureofNonConformance.SetFocus
 Me!NatureofNonConformance.Form.SomeControl.SetFocus
 DoCmd.GoToRecord , , acNewRec
Try setting focus to the FORM object in the first line:

 Me!NatureofNonConformance.FORM.SetFocus
 Me!NatureofNonConformance.Form.SomeControl.SetFocus
 DoCmd.GoToRecord , , acNewRec
Avatar of SparkyP

ASKER

Scott I get

There is an invalid method in expression when I add Form
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SparkyP

ASKER

Scott

Thank you for all your help. Your image made me think about the Tabbed Page. I needed to focus on the Page before moving to the subform and control.

Me!Page243.setfocus
Me!NatureofNonConformance.FORM.SetFocus
 Me!NatureofNonConformance.Form.NatureOfNC.SetFocus
 DoCmd.GoToRecord , , acNewRec

Thanks again for your patience.

Mark
Avatar of SparkyP

ASKER

Scott

 Thank you for all your help. Your image made me think about the Tabbed Page. I needed to focus on the Page before moving to the subform and control.

 Me!Page243.setfocus
 Me!NatureofNonConformance.FORM.SetFocus
  Me!NatureofNonConformance.Form.NatureOfNC.SetFocus
  DoCmd.GoToRecord , , acNewRec

 Thanks again for your patience.

 Mark
So for others who might find this:

You must focus on the Tab page first, THEN the Subform CONTROL, and finally a control on the subform.