Field can not be updated (1 Viewer)

Hanz

Registered User.
Local time
Yesterday, 16:58
Joined
Aug 9, 2018
Messages
25
Hi I have a simple recordset. the code is running okay until it reaches "rs!VesselID = txtVessel" in my code and it returds error 3164. I tried to manipulate the data in query form and I'm able to edit the field VesselID but when it is in recordseet it gives me an error. Please see my code below.


Option Compare Database
Option Explicit

Dim db As Database
Dim rs As Recordset

Private Sub Form_Load()
Set db = CurrentDb
Set rs = db.OpenRecordset("qry_AddJob")

FillForm
End Sub

Private Sub FillForm()

If Not rs.BOF And Not rs.EOF Then
Me.txtStorage = rs!StorageDate
Me.txtUnit = rs!TypeCargoID
Me.txtVessel = rs!VesselID
Me.txtCargoDescription = rs!CargoDescription
End If

Private Sub btnSave_Click()
' On Error Resume Next
rs.Edit
rs!StorageDate = Me.txtStorage
rs!TypeCargoID = Me.txtUnit
rs!CargoDescription = Me.txtCargoDescription
rs!VesselID = txtVessel
rs.Update
End Sub


End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:58
Joined
May 7, 2009
Messages
19,231
use DAO namespace:

Dim db As DAO.Database
Dim rs As DAO.Recordset

also need to requery the recordset

Private Sub Form_Load()
Set db = CurrentDb
Set rs = db.OpenRecordset("qry_AddJob", dbOpenDynaset)
End Sub

Private Sub FillForm()
rs.Requery
If Not rs.BOF And Not rs.EOF Then
rs.MoveFirst
Me.txtStorage = rs!StorageDate
Me.txtUnit = rs!TypeCargoID
Me.txtVessel = rs!VesselID
Me.txtCargoDescription = rs!CargoDescription
End If
End Sub

Private Sub btnSave_Click()
' On Error Resume Next
rs.FindFirst "VesselID=""" & Me.txtVessel & """"
If Not rs.NoMatch Then
rs.Edit
Else
.AddNew
End If
rs!StorageDate = Me.txtStorage
rs!TypeCargoID = Me.txtUnit
rs!CargoDescription = Me.txtCargoDescription
rs!VesselID = txtVessel
rs.Update
End Sub
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:58
Joined
May 7, 2009
Messages
19,231
but why are you using an Unbound form?
 

Hanz

Registered User.
Local time
Yesterday, 16:58
Joined
Aug 9, 2018
Messages
25
but why are you using an Unbound form?

I wanted to control my form that i could forward, back, edit, add and save w/o that access record selector.

I'm very new with access and any better option is highly appreciated.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:58
Joined
May 7, 2009
Messages
19,231
You csn remove the Record Selector on the form's property.
 

Hanz

Registered User.
Local time
Yesterday, 16:58
Joined
Aug 9, 2018
Messages
25
Yes i already removed the record selectors and added my buttons for next, previous, edit, save. this is the reason why i used recordset but got stuck with the vesselID.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 18:58
Joined
Feb 28, 2001
Messages
27,138
Don't want to seem like I'm second-guessing you, but I have had many bound forms AND removed the record selectors AND had the Next, Previous, Add, Remove, Save, Undo, etc. buttons and it all worked just fine. The command button wizards have the basics for everything I wanted to do on the bound form.

So the question has to be, what did you think Access did that stopped you from using the bound form?

As to error 3164, that is often based on record locking. For some reason, Access thinks that record is locked and thus cannot be updated at the moment. It OFTEN is the case that YOU YOURSELF are the one who has it locked in some way. If you have a query, verify that the query's properties include Optimistic Locking or even No Locks. You can also set that property for the form if you chose to bind it. I'm not saying that is your specific problem, but it is commonly seen and is therefore worth a quick look.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:58
Joined
Feb 19, 2013
Messages
16,607
perhaps vesselID is an autonumber and therefore cannot be updated?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 18:58
Joined
Feb 28, 2001
Messages
27,138
CJ - That could do it.

I didn't suggest it, but if it had been Relational Integrity I would have expected a different number. Then again I usually see that from the other side of the issue, changing the child's FK. If this is trying to reset the PK of the parent and cascade update isn't allowed, that might also have an undesired effect.
 

Users who are viewing this thread

Top Bottom