Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
821 views
in Technique[技术] by (71.8m points)

ms access - Making "DoCmd.GoToRecord" function work on a subform

I have been using the function DoCmd.GoToRecord , , acNewRec successfully for creating and moving to a new record within a subform (with a table as the source). However, when I try to do the same from the parent form, this does not work. I have tried different approaches, including:

Me.sbfrm_subform.Controls("ctrName").SetFocus
DoCmd.GoToRecord , , acNewRec

which only sets the focus on the control (ctrName), but fails to add and go to a new record, or

DoCmd.GoToRecord acDataForm, Me.sbfrm_subform.Form.Name, acLast

Which returns the runtime error 2489, "The object 'sbfrm_subform is nt open."

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try splitting the operations:

Me.[sbfrm_subform].SetFocus
DoCmd.GoToRecord, , acNewRec

Alternatively, you can try creating a public Sub in the subform, and since it becomes a method of the form you can use that.
Using this on recent versions of Access, you can even try playing directly with the form's recordset instead, like Me.Recordset.Movenext.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...