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

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
 
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:
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
 
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.
 
Actually, it's even simpler:
Code:
Private Sub cmdSubformNewRecord_Click()

  Me.SubformContainerName.SetFocus
  DoCmd.GoToRecord , , acNewRec

End Sub
 
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?
 
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.
 
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.
 
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.
 
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)
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.... 😁
 
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.
 
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

Back
Top Bottom