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, 06:32
Joined
May 21, 2018
Messages
8,529
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.
Not true! Plenty examples provided where code is launched from main form. Mine for example.
 

bmaccess

Member
Local time
Today, 03:32
Joined
Mar 4, 2016
Messages
78
Not true! Plenty examples provided where code is launched from main form. Mine for example.
Hi there. I liked you example. The adding of new records worked nicely. I will try again your example and see if it can work with my original application. I will let you know if I manage to get it going. Your code was the easiest and really liked it. All I need is to just get the new records populated correctly. Thanks
 
Last edited:

bmaccess

Member
Local time
Today, 03:32
Joined
Mar 4, 2016
Messages
78
Hi MajP. Your code work nicely, But it overwrites my current record. Any suggestions. I will happy if it works. Thanks

Private Sub cmdAddRecord_Click()
frmStudentBooksSubform.SetFocus
With Me.frmStudentBooksSubform.Form.Recordset
.AddNew
.Update
End With
frmStudentBooksSubform.SetFocus
With Me.frmStudentBooksSubform.Form
.BookTitle = Me.cmbBookNoTitle.Column(1)
.StudentBookIssue_ID = Me.cmbBookNoTitle.Column(0)
End With
 

LarryE

Active member
Local time
Today, 03:32
Joined
Aug 18, 2021
Messages
591
Hi MajP. Your code work nicely, But it overwrites my current record. Any suggestions. I will happy if it works. Thanks

Private Sub cmdAddRecord_Click()
frmStudentBooksSubform.SetFocus
With Me.frmStudentBooksSubform.Form.Recordset
.AddNew
.Update
End With
frmStudentBooksSubform.SetFocus
With Me.frmStudentBooksSubform.Form
.BookTitle = Me.cmbBookNoTitle.Column(1)
.StudentBookIssue_ID = Me.cmbBookNoTitle.Column(0)
End With
Where did you get this code?
 

ebs17

Well-known member
Local time
Today, 12:32
Joined
Feb 7, 2020
Messages
1,946
Code:
With Me.frmStudentBooksSubform.Form.Recordset
   .AddNew
   .Update
 End With
That's pretty much nonsense.
An empty record is created (=> hot air) and at best a auto value is burned. How long did you have to think about it to write something like that?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 06:32
Joined
May 21, 2018
Messages
8,529
I tested this code
That's pretty much nonsense.
An empty record is created (=> hot air) and at best a auto value is burned. How long did you have to think about it to write something like that?
Oops my fault. In the beginning of this thread we were simply trying to prove that you can do an add new and move to the last record. Along with demonstrating other things. After demoing that I should have fixed the code.

How about?
Code:
Private Sub cmdAddRecord_Click()
  dim rs as dao.recordset
  set rs = me.frmStudentBooksSubform.Form.Recordset
 rs.AddNew
    rs!BookTitle = Me.cmbBookNoTitle.Column(1)
    rs!StudentBookIssue_ID = Me.cmbBookNoTitle.Column(0)
  rs.update
end sub
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 11:32
Joined
Jul 21, 2014
Messages
2,280
@MajP, looks like there is an errant 'With' in your adjusted code (Or a missing 'End With' and a few surplus 'rs's).
 
Last edited:

bmaccess

Member
Local time
Today, 03:32
Joined
Mar 4, 2016
Messages
78
Hello guys. Thanks to you all. I have solve my original problem. I do not even need a button to add a new record. Once I added a record I just scroll down when I need to add another record.
1699310610067.png
 

Mike Krailo

Well-known member
Local time
Today, 06:32
Joined
Mar 28, 2020
Messages
1,044
Well, I for one am completely lost in this thread. No clue whatsoever.
 

LarryE

Active member
Local time
Today, 03:32
Joined
Aug 18, 2021
Messages
591
Hello guys. Thanks to you all. I have solve my original problem. I do not even need a button to add a new record. Once I added a record I just scroll down when I need to add another record.
View attachment 110818
Which, of course, is the opposite of what you said you wanted in Post #1. So all this time we gave you solutions you didn't even want or need. Well done bmaccess.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 06:32
Joined
May 21, 2018
Messages
8,529
I am almost thinking the whole thing was a prank and we all got played. If so well done.
 

bmaccess

Member
Local time
Today, 03:32
Joined
Mar 4, 2016
Messages
78
Hello guys. This was no prank. I am not here to waste your time and my time on pranks. To a certain degree the problem is solved when I am not using a scanner I can click in the combo box. When I tried using the scanning it looks like my problem not completely solve. I have notice on this forum and other forums that other people are asking the exact same thing that I am asking and nobody are able to solve it. I am still going to try and find a solution. Thanks
 

bmaccess

Member
Local time
Today, 03:32
Joined
Mar 4, 2016
Messages
78
Which, of course, is the opposite of what you said you wanted in Post #1. So all this time we gave you solutions you didn't even want or need. Well done bmaccess.
Testing using a scanner my problem is not solve. So I need to find code to solve my original problem again. But I am looking at all of your code to see what works and don't. I am greateful for all your input. Thanks
 

bmaccess

Member
Local time
Today, 03:32
Joined
Mar 4, 2016
Messages
78
If all fails the user must just click on the asterisk(*) to add a new new. MajP your Add new works, but the new record is not selected or have a blue bar on it to accept data immediately. That is what I want, when you say add new, a new record must be added and the whole record must be selected which means it must have the blue bar or selected at the same time. This is what i have been asking from the very start. Those interested in still helping me are most welcome. I try out all code people is suggesting.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 06:32
Joined
May 21, 2018
Messages
8,529
addnew.png


For the LOVE OF GOD, someone please explain to me how the added record is not selected in any of the three versions of code. I click on the button to add Stephen Lai and Steven Lai is added. Stephen Lai is selected with a blue bar and editable.
Its ADDED
Its SELECTED
Its BLUE BLUE BLUE BLUE....
hat is what I want, when you say add new, a new record must be added and the whole record must be selected which means it must have the blue bar or selected at the same time.
 

ebs17

Well-known member
Local time
Today, 12:32
Joined
Feb 7, 2020
Messages
1,946
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.
Never ever in the example file shown, and there the button is outside the subform.

some error somewhere
Not in the example. But probably in your work. You should separate them linguistically, and you should know and name exactly where you do something.

Alternatively, you could also contact the developer of your database, because with the "skills" shown here, I don't think you've created anything that works yourself. What you are doing here seems like a confused wandering around in an unfamiliar environment.
 

bmaccess

Member
Local time
Today, 03:32
Joined
Mar 4, 2016
Messages
78
View attachment 110855

For the LOVE OF GOD, someone please explain to me how the added record is not selected in any of the three versions of code. I click on the button to add Stephen Lai and Steven Lai is added. Stephen Lai is selected with a blue bar and editable.
Its ADDED
Its SELECTED
Its BLUE BLUE BLUE BLUE....
Yes, the record is Stephen Lai is BLUE. Write me code to give me a BLANK NEW RECORD under Stephen Lai and make it BLUE with no data in it thats what I am asking for.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 06:32
Joined
May 21, 2018
Messages
8,529
T
Yes, the record is Stephen Lai is BLUE. Write me code to give me a BLANK NEW RECORD under Stephen Lai and make it BLUE with no data in it thats what I am asking for.
That has been demonstrated 10 thousand times and every time you say that is not what you want. I think that was demoed in post 3 or 4. It was demoed using a recordset add new and using the docmd.
Code:
  Dim frm As Access.Form
  Set frm = Me.subFrmStudents.Form
  Me.subFrmStudents.SetFocus
  DoCmd.RunCommand acCmdRecordsGoToNew
  'or
  'Dim frm As Access.Form
  'Dim rs As DAO.Recordset
  'Set frm = Me.subFrmStudents.Form
  'Set rs = frm.Recordset
  'frm.Recordset.AddNew

Now this whole thing seems stupid. You said you wanted to populate the records from a combobox outside the subform. So why would you do this we will never know. The normal person would assume you select an item from the combobox and it creates a new record.

new.jpg


So now there is a new record
It is selected

SO HOW IS THIS NOT WHAT YOU WANT?
 

Users who are viewing this thread

Top Bottom