Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35
  1. #16
    Join Date
    Sep 2025
    Location
    Newport, Shropshire, UK
    Posts
    16
    However, when the form closes the new record DOES NOT SAVE..
    One scenario in which that would happen is where all controls in the form bound to Required columns have values set as their DefaultValue property, and the form is closed without amending any of the values or inserting a value into any other control. To accept the default values without amendment assign the value of any one of them to itself. That will Dirty the form and force the record to be saved.

  2. #17
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    None of the fields are required.

  3. #18
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Office 365
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,738
    Another sneaky possibility that can skip a form's update to a table is the form's before_insert event. This event is often used to validate data to prevent garbage updates. It is always called before a new record is created by the form and improper coding in the event can completely kill the update.

  4. #19
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Nope, Before_Insert not active.

    BTW, form works fine updating an existing record:
    Code:
    
    Private Sub Form_DblClick(Cancel As Integer)
    
    
    DoCmd.OpenForm "frmItemDescriptor", , , , acFormEdit, acDialog, ItemID
    
    
    End Sub
    So, at almost 10PM Sunday night, I got curious to see if I could brut force add a record with the AddNew but was greeted with another 3022 error when I hit the ".Update" statement, something I had previously tried when I was hosting two different tables. Now, I'm just trying to add a record to the form's RecordSource.
    Code:
    Private Sub lblSAVE_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Okay, everything required to enter a new record has been satisfied, copy fields to our main table.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim rsSav As DAO.Recordset
    Dim strTemp As String
    
    
    If strMode = "New" Then       'Current RecordSet is QInvNew
        Set rsSav = DBEngine(0)(0).OpenRecordset("tblInv")
        With rsSav
        
            .AddNew
            !Description = Me.tbItemDescription
            !Keep = Me.chkKeep
            !Donate = Me.chkDonate
            !Sold = Me.chkSold
            !Sell = Me.chkSell
            !Comment = Me.tbComment
            !Im1 = Me.tbImage1
            !Im2 = Me.tbImage2
            !Im3 = Me.tbImage3
            !Im4 = Me.tbImage4
            !Im5 = Me.tbImage5
            !Im6 = Me.tbImage6
            .Update
            
        End With
        
    rsSav.Close
    Set rsSav = Nothing
    End If
    
    
    DoCmd.Close acForm, "frmItemDescriptor"
    
    
    End Sub
    Last edited by GraeagleBill; 10-05-2025 at 10:48 PM.

  5. #20
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Can you add a record directly via the table interface?
    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

  6. #21
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Can you add a record directly via the table interface?
    I was also beginning to suspect a corrupted back-end DB, or at least the tblInv itself.

    1) So NO, my attempts to add a record was showing an autonumber that was an already used ItemID.
    2) There are only 48 records in the tblInv table, a new addition autonumber should have been 49 but the addition attempt was showing 15.
    3) A compact and repair followed by another attempt to add was successful.
    4) Normal record addtions via the form UI were also successful with the code path shown in #18 blocked.

    Pure supposition on my part, but I think a previous Update Query on the table left it corrupted.

    One lingering question: How would the main form know that its Recordsource has a new record added via a subordinate form?

  7. #22
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Store record count before and after and compare?
    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. #23
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Store record count before and after and compare?
    GOOD GRIEF! Another instance of the obvious!

    All you young'ns need to prepare yourselves for your abilities for the obvious. The aging brain is not always a happy place.

  9. #24
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Post 8 was moderated, I'm posting to trigger email notifications. Sorry for being slow, was away from my computer over the weekend.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #25
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Quote Originally Posted by GraeagleBill View Post
    GOOD GRIEF! Another instance of the obvious!

    All you young'ns need to prepare yourselves for your abilities for the obvious. The aging brain is not always a happy place.
    At 71, I would hardly class myself as a 'young'n'.
    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

  11. #26
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    At 71, I would hardly class myself as a 'young'n'

    Got ya beat by 19 years


    BTW, surprised that this code didn't work:
    Code:
    Private Sub cmdNewItem_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  User wants to add a new item to the inventory.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim lngCount As Long
    
    
    lngCount = Me.RecordsetClone.RecordCount
    DoCmd.OpenForm "frmItemDescriptor", , , , , acDialog
    Me.RecordsetClone.MoveLast
    If Me.RecordsetClone.RecordCount > lngCount Then Me.Requery
    
    
    End Sub

    My final solution:
    Code:
    Private Sub cmdNewItem_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  User wants to add a new item to the inventory.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim lngCount As Long
    
    
    lngCount = DCount("*", "QInv")
    DoCmd.OpenForm "frmItemDescriptor", , , , , acDialog
    If DCount("*", "QInv") > lngCount Then Me.Requery
    
    
    End Sub

  12. #27
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    I would expect you would need to MoveLast for the first count?
    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

  13. #28
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    I would expect you would need to MoveLast for the first count?

    No, still does not Requery:
    [CODE]
    Private Sub cmdNewItem_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' User wants to add a new item to the inventory.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim lngCount As Long


    'lngCount = DCount("*", "QInv")
    'DoCmd.OpenForm "frmItemDescriptor", , , , , acDialog
    'If DCount("*", "QInv") > lngCount Then Me.Requery


    Me.RecordsetClone.MoveLast
    lngCount = Me.RecordsetClone.RecordCount
    DoCmd.OpenForm "frmItemDescriptor", , , , , acDialog
    Me.RecordsetClone.MoveLast
    If Me.RecordsetClone.RecordCount > lngCount Then Me.Requery


    End Sub


    [CODE]

  14. #29
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    You're assigning recordsetclone.count to the variable lngCount then asking if one is greater than the other. How would that be possible? I don't see why the number would change with successive MoveLast moves on the same recordsetclone, which doesn't look like it's necessary to me.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #30
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Because form "frmItemDescriptor" might create a new item and the record count would increase as a result. If so, I need to Requery so the user can see the new addition.

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 29
    Last Post: 03-30-2025, 01:52 AM
  2. Replies: 13
    Last Post: 11-04-2019, 04:04 PM
  3. Replies: 4
    Last Post: 06-10-2018, 03:53 PM
  4. Replies: 1
    Last Post: 06-15-2017, 05:49 PM
  5. Replies: 2
    Last Post: 09-20-2014, 11:28 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