Going to a new record in a subform

J

Joanne

I have a form open called Frm Shift Activity that
contains a subform called SubFrm JobActivity. From
within another dialog box form I have the following code
whose intention it is to go to a new record in the
subform SubFrm JobActivity. But I get the following
message on the GoToControl method. "There is no field
named 'SubFrm JobActivity' in the current record.


Forms![Frm Shift Activity]![SubFrm JobActivity].Visible =
True
Forms![Frm Shift Activity]![PressID].SetFocus
DoCmd.GoToControl "SubFrm JobActivity"
DoCmd.GoToRecord , , acNewRec


How can I tell a subform to go to a new record from
within a totally different form?

Thanks
Joanne
 
L

Larry Linson

How can I tell a subform to go to a
new record from within a totally
different form?

Never tried it, but I'd consider changing the embedded Form in the Subform
Control to Data Entry Mode -- won't show the other records, but should allow
you to enter the new record... if you need to switch back, you could have a
command button on that form for "Show All Records" and change the properties
accordingly.

Larry Linson
Microsoft Access MVP
 
M

Marshall Barton

Joanne said:
I have a form open called Frm Shift Activity that
contains a subform called SubFrm JobActivity. From
within another dialog box form I have the following code
whose intention it is to go to a new record in the
subform SubFrm JobActivity. But I get the following
message on the GoToControl method. "There is no field
named 'SubFrm JobActivity' in the current record.


Forms![Frm Shift Activity]![SubFrm JobActivity].Visible =
True
Forms![Frm Shift Activity]![PressID].SetFocus
DoCmd.GoToControl "SubFrm JobActivity"
DoCmd.GoToRecord , , acNewRec


Double check the name of the subform ***control*** that's
displaying the subform. You need to use the control's name,
which may not be the name of the form in the control's
SourceObject property.

Be aware the GoToControl is a weak way of setting the focus.
You have two statements in a row that both set the focus.

I can't be sure here, but I think you want to use:

With Forms![Frm Shift Activity]![subformcontrol]
.Visible =True
.SetFocus
.Form.[anysubformcontrol].SetFocus
End With
DoCmd.GoToRecord , , acNewRec
 
G

Guest

Can I suggest that you remove the space in the subform name and see if that
helps otherwise try adding square brackets inside your double quotes to
surround the subform name. Otherwise I can't see any issue. Try to get in the
habit of NOT using spaces in your form names. I know it took me a while to
get used to it but it makes a lot of stuff more simple to code and work with.

Best of luck!

Marshall Barton said:
Joanne said:
I have a form open called Frm Shift Activity that
contains a subform called SubFrm JobActivity. From
within another dialog box form I have the following code
whose intention it is to go to a new record in the
subform SubFrm JobActivity. But I get the following
message on the GoToControl method. "There is no field
named 'SubFrm JobActivity' in the current record.


Forms![Frm Shift Activity]![SubFrm JobActivity].Visible =
True
Forms![Frm Shift Activity]![PressID].SetFocus
DoCmd.GoToControl "SubFrm JobActivity"
DoCmd.GoToRecord , , acNewRec


Double check the name of the subform ***control*** that's
displaying the subform. You need to use the control's name,
which may not be the name of the form in the control's
SourceObject property.

Be aware the GoToControl is a weak way of setting the focus.
You have two statements in a row that both set the focus.

I can't be sure here, but I think you want to use:

With Forms![Frm Shift Activity]![subformcontrol]
.Visible =True
.SetFocus
.Form.[anysubformcontrol].SetFocus
End With
DoCmd.GoToRecord , , acNewRec
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top