Results 1 to 3 of 3
  1. #1
    Travb81 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Aug 2014
    Posts
    18

    Trouble saving record on subform - Many to Many type relationship.

    I have an Access Front End, database is MariaDB. Interacting by Linked Tables.

    Basic structure:
    tblPeople
    ID
    FirstName
    Surname
    Phone
    tblCompanies
    ID
    Name
    tblPeopleCompanyLink
    ID
    PeopleID
    CompanyID

    I have a Companies Form.
    On that, I have a People subform, with the recordsource as a query: tblPeopleCompanyLink, left join on tblPeople.
    The People subform has a combobox, to select an ID from tblPeople. Works perfectly for selecting a record already in tblPeople.
    Click image for larger version. 

Name:	Capture1.PNG 
Views:	17 
Size:	11.5 KB 
ID:	35375


    If the combobox NotInList fires, I have this code to add a new record in tblPeople:


    Code:
        Me.Undo
        
        Dim rst As Recordset
        Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblPeople", dbOpenDynaset, dbSeeChanges)
        rst.AddNew
        
        rst!FirstName = NewData
        rst.Update
        rst.Close
        Response = acDataErrAdded
        Me.Dirty = False

    The problem...
    I try to enter some additional information such as [Phone], and when leaving the field, I get error "Field cannot be updated".
    I can't edit fields, until I click another record - and then go back to the new one I just created.
    I'm assuming I need to force a save / requery the data source somehow?



    Help greatly appreciated!

    I've played around with requery, bookmark's, docmd.runcmd accmdsaverecord - I'm sure i'm making this harder than it needs to be!

  2. #2
    Travb81 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Aug 2014
    Posts
    18
    To simplify this even more.... it's not related to the ComboBox NotInList code.
    If I use the ComboBox to select a PersonID - it will show me their name, phone number. I can edit these, but if I leave the record, I get the "Field cannot be updated" error.

    How can I select a PersonID, and have the record save/requery to allow me to edit these values immediately?

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You should not include tblPeople in the subform except to display its data, not edit. And it is not even necessary to include the table just to display people info. Expressions in textboxes can reference columns of combobox. Edits to tblPeople should be done in another form. If you want to add/edit people 'on the fly' during data entry, open a pop up form. Review https://blueclawdatabase.com/notinlist-event-code/
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Auto saving data from RECORD IN FORM TO SUBFORM
    By Detectiveclem in forum Access
    Replies: 3
    Last Post: 07-25-2018, 04:33 AM
  2. Replies: 6
    Last Post: 08-08-2014, 01:10 PM
  3. Replies: 2
    Last Post: 07-14-2014, 01:31 AM
  4. Replies: 6
    Last Post: 08-21-2013, 02:51 PM
  5. Replies: 2
    Last Post: 08-06-2012, 08:27 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