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

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:39
Joined
May 21, 2018
Messages
8,529
This ranks up to the absolutely stupidest thread I have ever participated in! I have never seen an OP unable to look at suggestions and provide comments and be unable to explain why it does not meet their needs or further explain their requirements.
@Gasman and @LarryE
I am tapping out and should have followed your lead and done it earlier.
Good luck.
fml-sylvester.gif
 

bmaccess

Member
Local time
Today, 04:39
Joined
Mar 4, 2016
Messages
78
Hi there.
This was all I ask.
I would like to know if there are code which I can put in a button outside a subform to select the new record on a subform. I do not want my user to click on the asterisk(*) to add data. Adding a new blank record
I made a video if this was unclear to all.
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 12:39
Joined
Jul 21, 2014
Messages
2,280
In your button code you can do:
Code:
Private Sub cmdSubformNewRecord_Click()

  Forms.YourFormName.SubformContainerName.Form.txtSomeTextboxName.SetFocus
  DoCmd.GoToRecord , , acNewRec

End Sub
Substitute the actual names for the form, subform container control (this may be different from the name of the subform used as its SourceObject, and the name of a textbox on the subform.

If the button is on the main form then you can use:
Code:
Private Sub cmdSubformNewRecord_Click()

  Me.SubformContainerName.Form.txtSomeTextboxName.SetFocus
  DoCmd.GoToRecord , , acNewRec

End Sub
 

ebs17

Well-known member
Local time
Today, 13:39
Joined
Feb 7, 2020
Messages
1,946
I will look at the db.
You probably haven't gotten around to it yet because you're pondering problems and having to make videos.
You can't allow yourself to be distracted, and problems are there for you to have, not for you to solve.

I would be curious to find out how you approach real tasks when you're dancing in circles for a week because of something trivial.
 

cheekybuddha

AWF VIP
Local time
Today, 12:39
Joined
Jul 21, 2014
Messages
2,280
Actually, it's even simpler:
Code:
Private Sub cmdSubformNewRecord_Click()

  Me.SubformContainerName.SetFocus
  DoCmd.GoToRecord , , acNewRec

End Sub
 

cheekybuddha

AWF VIP
Local time
Today, 12:39
Joined
Jul 21, 2014
Messages
2,280
You probably haven't gotten around to it yet because you're pondering problems and having to make videos.
You can't allow yourself to be distracted, and problems are there for you to have, not for you to solve.

I would be curious to find out how you approach real tasks when you're dancing in circles for a week because of something trivial.
How is this constructive?

Does it make you feel clever?
 

LarryE

Active member
Local time
Today, 04:39
Joined
Aug 18, 2021
Messages
591
In your button code you can do:
Code:
Private Sub cmdSubformNewRecord_Click()

  Forms.YourFormName.SubformContainerName.Form.txtSomeTextboxName.SetFocus
  DoCmd.GoToRecord , , acNewRec

End Sub
Substitute the actual names for the form, subform container control (this may be different from the name of the subform used as its SourceObject, and the name of a textbox on the subform.

If the button is on the main form then you can use:
Code:
Private Sub cmdSubformNewRecord_Click()

  Me.SubformContainerName.Form.txtSomeTextboxName.SetFocus
  DoCmd.GoToRecord , , acNewRec

End Sub
DoCmd.GoToRecord , , acNewRec will produce an error. Use:
DoCmd.RunCommand acCmdRecordsGoNew instead.
 

bob fitz

AWF VIP
Local time
Today, 12:39
Joined
May 23, 2011
Messages
4,727
I thought maybe there was a glimmer of hope. We will see. 😁 :rolleyes:
I think everybody should be able to see now. Remember the saying, "Abandon hope all ye who enter here".
 

cheekybuddha

AWF VIP
Local time
Today, 12:39
Joined
Jul 21, 2014
Messages
2,280
DoCmd.GoToRecord , , acNewRec will produce an error. Use:
DoCmd.RunCommand acCmdRecordsGoNew instead.
That's funny!
Code:
DoCmd.RunCommand acCmdRecordsGoToNew
'                              ^^
The above produced an error for me:
Run-time error '2046':

The command or action 'RecordsGoToNew' isn't available now.
 

ebs17

Well-known member
Local time
Today, 13:39
Joined
Feb 7, 2020
Messages
1,946
I don't like this DoCmd stuff. This always has a certain randomness because it is applied where the application believes it is current.
SetFocus is just a crutch.
If an object has a name, I can address it directly with that name. I don't have to put my finger on it to reach an understanding about who is meant.
This is a question of style.
When I talk to people, I don't have to tap them with my finger.
 

cheekybuddha

AWF VIP
Local time
Today, 12:39
Joined
Jul 21, 2014
Messages
2,280
If an object has a name, I can address it directly with that name. I don't have to put my finger on it to reach an understanding about who is meant.
This is a question of style.
I completely agree.

I have just seen your example in Post #59, and it is a much better solution than relying on SetFocus and DoCmd. (y)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:39
Joined
Feb 19, 2002
Messages
43,275
However your recommendation for an insert will never work if you do not pass a required field. So that is a less universal solution.
I would agree except that the OP thinks he has enough data in the main form to create the subform record once an item is selected from the list. That is why I suggested the append query originally.
 

LarryE

Active member
Local time
Today, 04:39
Joined
Aug 18, 2021
Messages
591
That's funny!
Code:
DoCmd.RunCommand acCmdRecordsGoToNew
'                              ^^
The above produced an error for me:
Run-time error '2046':

The command or action 'RecordsGoToNew' isn't available now.
I get no error at all after setting the focus to a sub-form from a parent form.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:39
Joined
Feb 19, 2002
Messages
43,275
I would be curious to find out how you approach real tasks when you're dancing in circles for a week because of something trivial.
I checked out when the OP refused to fix the schema. Having names for the student and book as the PK is just wrong.
 

mike60smart

Registered User.
Local time
Today, 12:39
Joined
Aug 6, 2017
Messages
1,905
Hi there.
This was all I ask.
I would like to know if there are code which I can put in a button outside a subform to select the new record on a subform. I do not want my user to click on the asterisk(*) to add data. Adding a new blank record
I made a video if this was unclear to all.
It would appear that you are not willing to take note of the advice given by most of the recognised experts on the Forum.

It would be easier if you can upload a copy of the database with no confidential data.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:39
Joined
May 21, 2018
Messages
8,529
I would like to know if there are code which I can put in a button outside a subform to select the new record on a subform. I do not want my user to click on the asterisk(*) to add data. Adding a new blank record
There has been 50+ threads that explain how to do exactly that with multiple techniques with demos too! Not a single example or code had the user click on the new record. All kinds of different ways. Append queries, recordset manipulation, and even the application methods Docmd. Yet, no one here can figure out why these solutions do not meet your needs, because you refuse to answer any simple questions.
 

LarryE

Active member
Local time
Today, 04:39
Joined
Aug 18, 2021
Messages
591
I checked out when the OP refused to fix the schema. Having names for the student and book as the PK is just wrong.
I was just going to say that. All of this doesn't matter anyway because looking at the design, I don't know how any of this can work.
I'm going to join the others in the bar for Re-Tox.... 😁
 

bmaccess

Member
Local time
Today, 04:39
Joined
Mar 4, 2016
Messages
78
I was just going to say that. All of this doesn't matter anyway because looking at the design, I don't know how any of this can work.
I'm going to join the others in the bar for Re-Tox.... 😁
Hi there. This program has been has been working for the last 3 years with no problems. All I would like to do now is an upgrade to the application so that a barcode scanner can be used to scan the books out on issues and scan in on return.
 

bmaccess

Member
Local time
Today, 04:39
Joined
Mar 4, 2016
Messages
78
Hi there all. Thank you for all the feedback. My apologies if you feel that I did not give you proper feedback on why the code did not work.
All of your code work if the Add New Record is inside the subform. When the Add New Record button is outside the subform unfortunately the code provided did not work or there were some error somewhere. Once again thanks to all for the comments and feedback.
I would like to thank GPGeorge for post #6. I used that post to solve the problem.
 

Users who are viewing this thread

Top Bottom