Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have inherited an ACCESS database from someone who has since left the company. It has a big form, which has plenty of dropdown and textbox controls. After filling them out, the user clicks a button to update the record to an external database.

This worked perfectly until three weeks ago, but now creates intermittent errors for most of the users. The problem is that the last two fields on the form do not always update. When that happens, the code generates a 3164: "Field cannot be updated" error message and the record is not updated. There are now about 1,000 records that have not been updated correctly.

There is a SQL SELECT statement which is used in a recordset which then becomes a storage place for all of the values of the controls on the form. Each of the controls has a tag in which is stored the name of the field (in the recordset) that should be updated with the control's value. So there is a loop, similar to:

VB
rs.Edit
For Each ctl In Me.Controls
                rs(ctl.Tag).value = ctl.value
Next
rs.Update


(There's some checking to ensure that we only use the correct type of controls, that the field identified by the tag value is actually in the recordset (rs), and that we haven't updated this record before with exactly the same values, but I left all that out for clarity)

I've debugged the module where it happens and the error is in the rs(ctl.Tag).value = ctl.value line. The code is in a Function which is defined as "Public Sub UpdateFields(ByVal rs As Recordset)"

The calling module created the recordset as follows:

VB
UpdateFields getRecNumSaveRS(txtRecNum)


(where getRecNumSaveRS is the name of a function that creates the recordset based on the record number passed as a parameter)

I modified the code to :

VB
Dim rs As Recordset
.
.
.
Set rs = getRecNumSaveRS(txtRecNum)
UpdateFields rs
rs.Close
Set rs = Nothing


... because I knew that not closing and disposing of the recordset could cause bugs, but it didn't seem to help.

There aren't any other people with an IT background in our group, so I don't have any help. If anybody can offer any help, I can check back here, or you might like to email me at ian-dot-n-dot-dennis-at-healthnet-dot-com

What I have tried:

1) Googling everywhere
2) Adding breakpoints to find WHERE the code errors out (it is BEFORE the rs.Update)
3) Adding rs.Close and Set rs = Nothing
4) adding timers to try to re-run the rs(ctl.Tag).value = ctl.value line (taken out again because they didn't help)
5) Checking that the correct version of the app was being used

Nothing works (trouble is it works mostly on my machine and is difficult to emulate)
Posted
Updated 28-Jun-16 5:00am
v2
Comments
CHill60 23-Jun-16 18:13pm    
I have obfuscated your email address to avoid spam bots picking it up. It's never a good idea to post your email in open forums on the internet

1 solution

It's quite convoluted and uncommon, and might get done in a better/simpler way, but you could start by passing the recordset by reference:
VB
Public Sub UpdateFields(ByRef rs As DAO.Recordset)
 
Share this answer
 
Comments
Member 12600972 28-Jun-16 18:55pm    
Great idea, and implemented because it helps with the disposal of the record set, however, we still get the same error (not on MY machine, tho :) )
Gustav Brock 29-Jun-16 4:50am    
You would also have to double-check the value you try to update with:

rs(ctl.Tag).Value = ctl.Value

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900