Results 1 to 12 of 12
  1. #1
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136

    Adding records to form

    Hi,


    I have a form that is controlled by what is selected in an unbound box in the header. I added an Add Record button and it opens a new empty record in the form. However, when I click to add data into that new record, it adds another blank record below it. How do I stop that from happening?

    I'm missing something, I just don't know what it is. Here is the only code I have in there now....

    Private Sub cmd_Add_Record_Click()
    Me.AllowAdditions = True
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    The AllowAdditions property of the form does not add a new record in itself, it simply allows or denies the additions. Use DoCmd.GoToRecord , , acNewRec to do it in VBA:

    https://www.techonthenet.com/access/modules/new_rec.php

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    Quote Originally Posted by Gicu View Post
    The AllowAdditions property of the form does not add a new record in itself, it simply allows or denies the additions. Use DoCmd.GoToRecord , , acNewRec to do it in VBA:

    https://www.techonthenet.com/access/modules/new_rec.php

    Cheers,
    Vlad
    Sorry I'm such a novice. It's not working. What am I missing? I replaced the AllowAdditions command with the below and it gives me an error. With AllowAdditions it actually gives me a new blank record. With the below I get nothing.

    Private Sub cmd_Add_Record_Click()


    DoCmd.GoToRecord , , acNewRec


    End Sub

  4. #4
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Open the form in design mode and in the form properties box set the AllowAdditions to Yes (=True). Now the code should work.

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Perhaps the "Data Entry" property is set to YES?
    Open the form in design mode, open the form property sheet, click on the "Data" tab, look at "Data Entry" - ensure it is set to NO...

  6. #6
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    Quote Originally Posted by Gicu View Post
    Open the form in design mode and in the form properties box set the AllowAdditions to Yes (=True). Now the code should work.

    Cheers,
    Vlad
    So it works, but it's still doing the same thing as before. I click add a record, a new record form appears, I start typing in any box and a new blank row appears beneath that one. I don't want that new row to appear.

    Not sure if it matters, but I'm using a multiple items form. So when I select from an unbound box in the header section, it shows a number of records for that product that have data. When I click add record it creates a blank record to add data.

  7. #7
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    You cannot stop that, it is the default way Access handles new records (soonest the "new" record gets some info and gets saved the new one appears). What is wrong with that, why would you want to suppress it? You need to provide more info on your intentions, but keep in mind that over-restricting "built-in" functionality usually is frustrating to your users.
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    Quote Originally Posted by ssanfu View Post
    Perhaps the "Data Entry" property is set to YES?
    Open the form in design mode, open the form property sheet, click on the "Data" tab, look at "Data Entry" - ensure it is set to NO...
    It is already set to no.

  9. #9
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    Quote Originally Posted by Gicu View Post
    You cannot stop that, it is the default way Access handles new records (soonest the "new" record gets some info and gets saved the new one appears). What is wrong with that, why would you want to suppress it? You need to provide more info on your intentions, but keep in mind that over-restricting "built-in" functionality usually is frustrating to your users.
    It's problematic because it's creating and saving a blank record on the form. It doesn't save the record to the table mind you (because it's blank), but when you select that product from the dropdown list in the future, the form shows a blank record benith the other records with data.

    It's just like what happens when you enter data into a table...it adds a row at the end with the *. Except it's doing it with my form. Is there a way to maybe always make that * row not visible in the form?

  10. #10
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Sorry, but I'm not following you, you say you don't end up with empty records in the table (good) but is saving a blank record on the form - it is not - it is just displaying a new record-placeholder on the form. Again, this is the default behaviour for Access forms that allow new data entry.

    To do what you want (suppress the new record) you need to manipulate the AllowAdditions property of the form. So for example you set it to No by default so you don't see the new record when you open the form, then in your Add New Record button's Click event you turn it on:
    Code:
    Private Sub cmd_Add_Record_Click()
    Me.AllowAdditions = True
    DoCmd.GoToRecord , , acNewRec
    End Sub
    And finally you need to turn it off again, probably in the form's AfterUpdate event once the new record was created:

    Code:
    Private Sub Form_AfterUpdate()
    If Me.AllowAdditions = True Then Me.AllowAdditions = False
    End Sub
    In my opinion all this is not really warranted, I think educating users about the default Access behaviour would be preferred...

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #11
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    Quote Originally Posted by Gicu View Post
    Sorry, but I'm not following you, you say you don't end up with empty records in the table (good) but is saving a blank record on the form - it is not - it is just displaying a new record-placeholder on the form. Again, this is the default behaviour for Access forms that allow new data entry.

    To do what you want (suppress the new record) you need to manipulate the AllowAdditions property of the form. So for example you set it to No by default so you don't see the new record when you open the form, then in your Add New Record button's Click event you turn it on:
    Code:
    Private Sub cmd_Add_Record_Click()
    Me.AllowAdditions = True
    DoCmd.GoToRecord , , acNewRec
    End Sub
    And finally you need to turn it off again, probably in the form's AfterUpdate event once the new record was created:

    Code:
    Private Sub Form_AfterUpdate()
    If Me.AllowAdditions = True Then Me.AllowAdditions = False
    End Sub
    In my opinion all this is not really warranted, I think educating users about the default Access behaviour would be preferred...

    Cheers,
    Vlad
    You got it. It's the new record placeholder that was popping up. I implemented your changes....it still pops up but now when I save the form it dissapears. That's good enough for me! Thank you so much for your help!!

  12. #12
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Your using a continuous form. Why not just use a single form?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Adding records from a form using VBA
    By Aeonem in forum Forms
    Replies: 15
    Last Post: 01-13-2015, 03:43 PM
  2. Adding Records with a Form
    By dylcon in forum Programming
    Replies: 12
    Last Post: 05-29-2013, 06:32 AM
  3. Adding multiple records from one form
    By sotssax in forum Forms
    Replies: 8
    Last Post: 07-17-2011, 11:16 AM
  4. Replies: 10
    Last Post: 01-10-2011, 07:52 PM
  5. adding records through form
    By Rayk in forum Forms
    Replies: 1
    Last Post: 01-09-2010, 07:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums