By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,940 Members | 611 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,940 IT Pros & Developers. It's quick & easy.

Add New Record to sub form

P: 49
I am having difficulity with a form.
I have a form with a sub form. I have a command button on the form that is to add a new record to the sub form.
Can someone help with code for this. I have tried several things and nothing seems to work. I have searched and searched but have had no luck.
btw teh command button can't be on the sub form.
Thanks
Jan 11 '08 #1
Share this Question
Share on Google+
7 Replies


puppydogbuddy
Expert 100+
P: 1,923
I am having difficulity with a form.
I have a form with a sub form. I have a command button on the form that is to add a new record to the sub form.
Can someone help with code for this. I have tried several things and nothing seems to work. I have searched and searched but have had no luck.
btw teh command button can't be on the sub form.
Thanks
You did not provide much info to go on, but I provided the following button code for you to try based on the following assumptions:
1.button is on the mainform
2. master and child links have been set between form and subform via the subform control on the main form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourButton_Click
  2.  If Me!YourSubformControl.Form.Dirty Then
  3.         Me!YourSubformControl.Form.Dirty = False
  4.  End If
  5.  
  6.  Me!YourSubform.SetFocus
  7.  
  8.  DoCmd.GoToRecord , , acNewRec
  9.  
  10. End Sub
Jan 12 '08 #2

P: 49
Thanks
That wors pefectly
Jan 14 '08 #3

P: 6
I think my problem is similar. I have a form with several subforms on different tabs. I created command buttons to open the subforms if the item does not appear in the lookup list in the main form. For example, Upon entering a person's information, when you get to the school field and the school you need is not listed, there is a command button to Add School (which calls on a macro that simply opens school subform). It allows the user to add the new record to the school subform, but it does not refresh the look up list in the main form. If I close the main form and reopen it it appears in the lookup list.
I tried the code in the previous post but it didn't work for me. I am pretty sure it is something I am doing wrong. I should have prefaced all this with the fact I am not a VBA programmer, but you have probably figured that out by now. :)
Thanks everyone for reading my post. I hope someone can help.
Jan 28 '08 #4

puppydogbuddy
Expert 100+
P: 1,923
I think my problem is similar. I have a form with several subforms on different tabs. I created command buttons to open the subforms if the item does not appear in the lookup list in the main form. For example, Upon entering a person's information, when you get to the school field and the school you need is not listed, there is a command button to Add School (which calls on a macro that simply opens school subform). It allows the user to add the new record to the school subform, but it does not refresh the look up list in the main form. If I close the main form and reopen it it appears in the lookup list.
I tried the code in the previous post but it didn't work for me. I am pretty sure it is something I am doing wrong. I should have prefaced all this with the fact I am not a VBA programmer, but you have probably figured that out by now. :)
Thanks everyone for reading my post. I hope someone can help.
According to Site rules, you are supposed to post your own question, and not piggy back on someone elses post. Nonetheless, your problem appears pretty easy to solve. In your button Add School, place the following code line after the code to add the school to the subform. Assuming your button is on the main form:

Me.YourLookupListName.Requery
Jan 29 '08 #5

P: 6
Thanks!! I will give it a try.
Jan 29 '08 #6

P: 14
I am having difficulity with a form.
I have a form with a sub form. I have a command button on the form that is to add a new record to the sub form.
Can someone help with code for this. I have tried several things and nothing seems to work. I have searched and searched but have had no luck.
btw teh command button can't be on the sub form.
Thanks
me![sbfXXXX].setfocus
docmd.gotorecord ,,acnewrec
Jan 30 '08 #7

puppydogbuddy
Expert 100+
P: 1,923
TerryDM,

See Post#3 1-14-2008.....your answer is similar to my answer that was accepted.
Jan 30 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.