Solved How do I move to a new record automatically in a subform

Hi all. I want nothing to be added to the new record. I have code that will add the data in the new record. All I require is that the new record in the subform must get the focus and ready to accept the data. I hope this may help. Any suggestions. Thanks.

Set focus to the sub-form and then in that context, issue a DoCmd.GoToRecord acNewRecord - which you can look up before you do it just to see the nuances of what it does.

 
It might well do, but then that code will add a new record, or you could just try
DoCmd.GoToRecord and the acNewRec option after setting focus?
 
You can try:
Code:
Me.FrmStudentBookSubForm.SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew
This code will set the focus to your sub-form and then go to a new record on the sub-form.
 
Hi there

Private Sub cmdAddRecord_Click()

frmStudentBooksSubform.SetFocus

DoCmd.GoToRecord acNewRecord ------> this line creates an error. After subform has setFocus

End Sub

Thanks
Thanks I will try this.
 
You're missing two commas:
DoCmd.GoToRecord , , acNewRecord
 
Code in the Add Button

Private Sub cmdAddRecord_Click()
frmStudentBooksSubform.SetFocus
DoCmd.GoToRecord , , acNewRecord
End Sub

1699026079687.png

You're missing two commas:
DoCmd.GoToRecord , , acNewRecord
 
I have found using:
DoCmd.RunCommand acCmdRecordsGoToNew
works better than:
DoCmd.GoToRecord acActiveDataObject, , acNewRec
when you are setting the focus to a different form. You get an error message like you did.
 
I have found using:
DoCmd.RunCommand acCmdRecordsGoToNew
works better than:
DoCmd.GoToRecord acActiveDataObject, , acNewRec
when you are setting the focus to a different form. You get an error message like you did.
Hi there.
Same error with this code too.


Private Sub cmdAddRecord_Click()
frmStudentBooksSubform.SetFocus
DoCmd.GoToRecord acActiveDataObject, , acNewRec
End Sub


1699029638754.png
 
This is what I need after ADD RECORD is pressed. I have to click on asterisk otherwise I cannot add a record . I do not want my users to go click on the asterisk.

1699029949236.png
 
When you are setting the focus from a parent form to a sub-form, you use:
Me.frmStudentBooksSubform.SetFocus
Not:
frmStudentBooksSubform.SetFocus
 
Hi there .
The error is not with the setFocus. The error is with the DoCmd... line

1699031872738.png
 
Have you looked to see what acActiveDataObject actually is?
 
You are over thinking this.
 

Attachments

Well then, as I said previously, try using:
DoCmd.RunCommand acCmdRecordsGoToNew
 
S
You are over thinking this.
Sir. You are correct. We are overthinking this simple problem. I am going back to basic just try to navigate as the records. That is what I am going to try now. I will download you and maybe you have simple solution. Thanks. Will let you know if it solve my problem.
 
S
You are over thinking this.
Sir. You are correct. We are overthinking this simple problem. I am going back to basic just try to navigate as the records. That is what I am going to try now. I will download you and maybe you have simple solution. Thanks. Will let you know if it solve my problem.

Okay I looked at the code. The blank new records are nice added. Now how can we automatically have the new record be selected ( the whole record is BLUE) or active. Thanks. The solution is 90% there. Much appreciated.


1699042979861.png


I need this now please.
1699043053853.png
 

Users who are viewing this thread

Back
Top Bottom