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

    Record won't save with AutoNumber

    Hi all,
    I have a table with an autonumber. I have a form where users can add records to that table. The autonumber field "ID" will be hidden on the form, I'm just displaying it for testing. Problem is, when I add a new record it populates the ID field but it won't let me save it saying it's blank. What am I missing?


    This is the save command the user clicks to save the record.

    Code:
    Private Sub cmdSave_Click() Saved = True
       DoCmd.RunCommand (acCmdSaveRecord)
       Me.cmdSave.Enabled = False
       Saved = False
       Me.Requery
       
    End Sub
    Click image for larger version. 

Name:	Screenshot 2025-08-07 112324.png 
Views:	19 
Size:	15.6 KB 
ID:	53175



  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Upload the DB with enough to see the issue.
    You are not telling everything here, not purposefully I admit, but something else is going on.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by Welshgasman View Post
    Upload the DB with enough to see the issue.
    You are not telling everything here, not purposefully I admit, but something else is going on.
    How do I upload it? It says the limit is 500kb.

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,820
    The example Form is showing the "Plant Code ID" as the PK and is displaying (New). When you enter new data for this record and then move to a new Record or Exit the Form, the data would be saved automatically.
    There would be no need for the ON Click Save Event.

  5. #5
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,820
    At the Top of the Site click on the Tab "How to Attach Files"

  6. #6
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by mike60smart View Post
    The example Form is showing the "Plant Code ID" as the PK and is displaying (New). When you enter new data for this record and then move to a new Record or Exit the Form, the data would be saved automatically.
    There would be no need for the ON Click Save Event.
    I know, but the users requested this On Click event. I'm sure this is where the problem is, but I just don't know why.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Quote Originally Posted by matey56 View Post
    How do I upload it? It says the limit is 500kb.
    You can create a new db and import just what is needed. By the looks of it, that will be just a table and the form?

    In future for full DBs, Save a copy, compact that, then zip it, then upload.

    Do you have Option Explicit at the top of each module/form/report?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by Welshgasman View Post
    You can create a new db and import just what is needed. By the looks of it, that will be just a table and the form?

    In future for full DBs, Save a copy, compact that, then zip it, then upload.

    Do you have Option Explicit at the top of each module/form/report?
    I zipped it this time.
    Attached Files Attached Files

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    I do not see that form?
    OK, found it.
    That form has the dbo_ table as source, no autonumber field in that table?

    I have no clue what you have done.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2021
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    The recordsource for the form is wrong table.

  11. #11
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by Welshgasman View Post
    I do not see that form?
    OK, found it.
    That form has the dbo_ table as source, no autonumber field in that table?

    I have no clue what you have done.
    Sorry, that's an old version. Disregard the dbo_70 table. The form should be based on tblPlantCode. I still get the error when using it as the record source.

  12. #12
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    OK, I figured it out. I had an extra field in the table that I didn't need and was set as required. Sorry to bother!

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Yes, you were not matching fields to sources.
    Attached Files Attached Files
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 1
    Last Post: 07-12-2023, 08:24 AM
  2. Replies: 7
    Last Post: 08-28-2017, 02:50 PM
  3. Report won't Save or Save As
    By DMJ in forum Reports
    Replies: 1
    Last Post: 02-03-2015, 05:46 PM
  4. Replies: 4
    Last Post: 11-21-2013, 05:06 PM
  5. Replies: 2
    Last Post: 01-15-2013, 10:04 PM

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