Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    BruceUK is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    48

    Problem with run time error 3164 - field cannot be updated

    Hi everyone - I'm using Access 365 under Windows 10.



    I have a VBA procedure that includes the following code to add a new record to a table:

    With rstSolution
    .AddNew
    !lngProblemNumber = 1
    !lngSolutionNumber = lngVBACount0
    !lngNumberOfValuesUsed = lngVBASolutionNumberOfProvidedValuesUsed(lngVBACou nt0)
    !strConsolidatedComponent = strVBAConsolidatedComponent(lngVBACount0)
    .Update
    End With

    When I run the code, I'm getting a run time 3164 error (Field cannot be updated). When I click the Debug option, the statement !lngSolutionNumber = lngVBACount0 is highlighted.

    The explanation given in the help info says that another user or process has locked the relevant table - but I'm the only user! There is no other process running at the time either.

    Can someone please explain why this would be happening and suggest a workaround. Is there a way of explicitly unlocking the table within VBA code?

    Thanks in advance for any help!

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Is rstSolution based on the forms data you are in?
    If it is that's your problem.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    BruceUK is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    48
    Quote Originally Posted by Minty View Post
    Is rstSolution based on the forms data you are in?
    If it is that's your problem.
    Thanks but I don't think that applies here. The controls on the form that is used to trigger this procedure are actually all unbound, so the form is not based on an underlying table or query. The rstSolution recordset is sourced by a query based on two related tables, but the VBA procedure derives the data to be written to these tables from the values entered on the form.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Is lngVBACount0 defined as an autonumber in the table? Autonumbers cannot be updated.

  5. #5
    BruceUK is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    48
    Quote Originally Posted by davegri View Post
    Is lngVBACount0 defined as an autonumber in the table? Autonumbers cannot be updated.
    No, the Solution Number attribute in the Solution table is just defined as a Number. In any case, I'm trying to create a new record in the table, not update an existing one.

    The two tables I referred to in my previous answer are tblProblem and tblSolution. These are in a one-to-many relationship (a problem can have more than one solution) and their primary keys are, respectively:

    lngProblemNumber
    lngProblemNumber, lngSolutionNumber.

    The VBA procedure first deletes any existing records in the two tables. Then it writes a new record to tblProblem using a similar .AddNew set of statements, and this is working OK. The error occurs at a later point when it tries to write the first record to tblSolution. As I mentioned, it fails at the assignment statement for the lngSolutionNumber attribute, so it doesn't seem to mind setting the lngProblemNumber attribute. I don't know whether this might be a clue.

    Any more ideas?

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by BruceUK View Post
    No, the Solution Number attribute in the Solution table is just defined as a Number. In any case, I'm trying to create a new record in the table, not update an existing one.
    Still cannot set an AutoNumber?
    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

  7. #7
    BruceUK is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    48
    But it's NOT an Autonumber!

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Put a break on that line and when you get there, open the table and look for the lock icon on any record? If you see it, something else or some part of the procedure that we can't see has put a lock on it.
    Or compact and zip a db copy and post that here.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by BruceUK View Post
    But it's NOT an Autonumber!
    I never said it was?, I was responding to your 'In any case' logic?
    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
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Just a thought, you could try to change your code and use Currentdb.Execute "Insert Into...." and see if that works.

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

  11. #11
    BruceUK is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    48
    Quote Originally Posted by Gicu View Post
    Just a thought, you could try to change your code and use Currentdb.Execute "Insert Into...." and see if that works.

    Cheers,
    Vlad
    Hi Vlad, thanks for this idea. I've changed the code as you suggested, but I'm now getting a run-time error 3061: "Too few parameters. Expected 3"

    The statement I've used is:

    Currentdb.Execute "Insert Into tblSolution (lngProblemNumber, lngSolutionNumber, lngNumberOfValuesUsed, strConsolidatedComponent) VALUES (1, lngVBACount0, lngVBAValues, strVBAComponent)"

    Can you see anything wrong with this? I haven't used this Insert Into statement before, so I might have misunderstood something.

    I have a nasty feeling that, even if I can get past this error, it might still give the original run time error 3164, but one error at a time!

  12. #12
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Try it this way. The debug.print will show the values of the update variables when the syntax is right. Note delimiters around the string variable.

    Code:
    dim sSQL as string
    sSQL= "Insert Into tblSolution (lngProblemNumber, lngSolutionNumber, lngNumberOfValuesUsed, strConsolidatedComponent) VALUES (1"  & ", " & lngVBACount0 & ", " &  lngVBAValues & ", '" &  strVBAComponent & "')"
    debug.print sSQL
    Currentdb.Execute sSQL, dbFailOnError

  13. #13
    BruceUK is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    48
    Quote Originally Posted by davegri View Post
    Try it this way. The debug.print will show the values of the update variables when the syntax is right. Note delimiters around the string variable.

    Code:
    dim sSQL as string
    sSQL= "Insert Into tblSolution (lngProblemNumber, lngSolutionNumber, lngNumberOfValuesUsed, strConsolidatedComponent) VALUES (1"  & ", " & lngVBACount0 & ", " &  lngVBAValues & ", '" &  strVBAComponent & "')"
    debug.print sSQL
    Currentdb.Execute sSQL, dbFailOnError
    Hi, many thanks - that seems to have worked.

    The only thing is that, during execution, a dialog box is appearing very briefly then disappearing before I can see what it is showing!

    And I'm still puzzled about why this Insert Into statement works when my original approach based on the recordset and using .AddNew gave the error. Do you have any idea why that would be the case?

  14. #14
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    And I'm still puzzled about why this Insert Into statement works when my original approach based on the recordset and using .AddNew gave the error. Do you have any idea why that would be the case?
    I've run into problems like that when trying to use sql updates behind a BOUND form. I don't often user unbound forms so can't comment on that.

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Could it be the composite primary key? Can you try to add an auto number PK instead and see what happens?
    Cheers,

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 19
    Last Post: 06-02-2019, 12:06 PM
  2. Runt time error 3164 field can not be updated
    By sprtrmp in forum Programming
    Replies: 12
    Last Post: 10-27-2015, 07:06 AM
  3. Replies: 6
    Last Post: 07-24-2014, 08:18 AM
  4. Field Cannot be updated - Error
    By aamer in forum Access
    Replies: 14
    Last Post: 06-21-2014, 05:20 AM
  5. Error # 3164 "field cannot be updated"
    By bbrazeau in forum Access
    Replies: 3
    Last Post: 08-29-2013, 01:18 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