Solved How do I move to a new record automatically in a subform (1 Viewer)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:35
Joined
Feb 28, 2001
Messages
27,273
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.

 

Gasman

Enthusiastic Amateur
Local time
Today, 21:35
Joined
Sep 21, 2011
Messages
14,395
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?
 

LarryE

Active member
Local time
Today, 13:35
Joined
Aug 18, 2021
Messages
599
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.
 

bmaccess

Member
Local time
Today, 13:35
Joined
Mar 4, 2016
Messages
78
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.
 

bob fitz

AWF VIP
Local time
Today, 21:35
Joined
May 23, 2011
Messages
4,726
You're missing two commas:
DoCmd.GoToRecord , , acNewRecord
 

bmaccess

Member
Local time
Today, 13:35
Joined
Mar 4, 2016
Messages
78
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:35
Joined
Feb 19, 2002
Messages
43,411
I think my problem looks like it is not understood properly so I simplify it.
Did you try running an append query? Then you can requery the subform to see the new record.
 

LarryE

Active member
Local time
Today, 13:35
Joined
Aug 18, 2021
Messages
599
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.
 

bmaccess

Member
Local time
Today, 13:35
Joined
Mar 4, 2016
Messages
78
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
 

bmaccess

Member
Local time
Today, 13:35
Joined
Mar 4, 2016
Messages
78
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
 

LarryE

Active member
Local time
Today, 13:35
Joined
Aug 18, 2021
Messages
599
When you are setting the focus from a parent form to a sub-form, you use:
Me.frmStudentBooksSubform.SetFocus
Not:
frmStudentBooksSubform.SetFocus
 

bmaccess

Member
Local time
Today, 13:35
Joined
Mar 4, 2016
Messages
78
Hi there .
The error is not with the setFocus. The error is with the DoCmd... line

1699031872738.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:35
Joined
Sep 21, 2011
Messages
14,395
Have you looked to see what acActiveDataObject actually is?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:35
Joined
May 21, 2018
Messages
8,555
You are over thinking this.
 

Attachments

  • Addnew.accdb
    1.5 MB · Views: 48

LarryE

Active member
Local time
Today, 13:35
Joined
Aug 18, 2021
Messages
599
Well then, as I said previously, try using:
DoCmd.RunCommand acCmdRecordsGoToNew
 

bmaccess

Member
Local time
Today, 13:35
Joined
Mar 4, 2016
Messages
78
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.
 

bmaccess

Member
Local time
Today, 13:35
Joined
Mar 4, 2016
Messages
78
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

Top Bottom