Results 1 to 6 of 6
  1. #1
    pdevito3 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Aug 2013
    Posts
    35

    Junction Tables and 3164 Errors

    Hi all,

    I have an events table and a junction table that has a composite key with two fields; those are the only fields on the junction table and are FKs in my events table.

    I have a form that fills in events to my events table and also fills in values to my junction table. The control source is a query of the two tables along with a couple of other reference tables for metadata associations. The form works fine... the first time. My problem is that, after I have entered an event that has my unique composite key for the first time (thereby entering a new record to my junction table), once I go to enter a second event that uses the same key, access tries to enter the record again and throwing a "3164: field cannot be updated" error instead of referencing the already created composite key.

    Some other helpful info: I have the form set the composite values to the selected values on form load. Normally, I would just set the primary key to the primary key values and access would follow my logic, but in this case it always tries to make a new record.



    Any ideas? What gives?

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    I think this might be Access's predictability 'mode?'.
    Like when you are typing in data into a table, it predicts youre going to enter that text again, and fills it in for you.
    This is good for lots o data entry, but BAD when entering indexes.

  3. #3
    pdevito3 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Aug 2013
    Posts
    35
    Soooo what would you suggest?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    You have an Events table and a "junction table". What is the subject matter of this database?
    What is the design of the junction table?
    Can you post a jpg of your relationships window, or a copy of your database?

    More info on junction tables at this TrainSignal tutorial.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    If you want to provide db for analysis, follow instructions at bottom of my post.

    I deleted the duplicate thread.
    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.

  6. #6
    pdevito3 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Aug 2013
    Posts
    35
    For those that end up here with the same issue, I resolved it by:

    1) Removing the fields causing the issue from the control source
    2) On form open, add similar code to below to insert the values into the table directly if needed.

    This isn't ideal, as a record will be created even if the user cancels and doesn't actually create a record, but since this is just a composite table used for calculations, it was an acceptable workaround for me. Hope this helps someone!

    Code:
    Private Sub Form_Open(Cancel As Integer)
    On Error GoTo Err_Handler
     
    Dim exceptionSQL As String
    Dim checkSQL As String
    Dim existsRS As DAO.Recordset
     
    Set existsRS = CurrentDb.OpenRecordset("SELECT tblAppointmentException.AppointmentID, tblAppointmentException.InstanceID From tblAppointmentException;") 'WHERE (((tblAppointmentException.AppointmentID)=" & Me.AppointmentID & _
        ") AND ((tblAppointmentException.InstanceID)=" & Me.InstanceID & "));")
        existsRS.FindFirst ("AppointmentID = " & Forms!frmMain!frmAppointmentLogSub.Form!AppointmentID & " AND InstanceID = " & Forms!frmMain!frmAppointmentLogSub.Form!InstanceID)
        If existsRS.NoMatch Then
            exceptionSQL = "INSERT INTO " _
                                & "tblAppointmentException (AppointmentID,InstanceID) " _
                                & " VALUES ('" & Forms!frmMain!frmAppointmentLogSub.Form!AppointmentID & "'," _
                                & "'" & Forms!frmMain!frmAppointmentLogSub.Form!InstanceID & "')"
            DoCmd.SetWarnings False
            DoCmd.RunSQL exceptionSQL
            DoCmd.SetWarnings True
        Else
            Set existsRS = Nothing
        End If
       
        Set existsRS = Nothing
       
    Exit_Handler:
        Set existsRS = Nothing
        Exit Sub
       
    Err_Handler:
        Call LogError(Err.Number, Err.Description, conMod & ".Form_Unload")
        Resume Exit_Handler
       
    End Sub

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

Similar Threads

  1. Help with Junction Tables
    By sbart in forum Access
    Replies: 5
    Last Post: 02-17-2014, 12:53 PM
  2. Populate Junction Table related to 3 Tables
    By Daoud1987 in forum Access
    Replies: 5
    Last Post: 12-11-2013, 12:13 PM
  3. Replies: 10
    Last Post: 05-29-2013, 11:39 AM
  4. Replies: 10
    Last Post: 07-12-2011, 11:09 PM
  5. Importing from Excel and Junction tables
    By fatalmusic in forum Import/Export Data
    Replies: 0
    Last Post: 04-07-2011, 07:11 AM

Tags for this Thread

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