Full Version: Field Can Not Be Updated Openargs Error In Access 2007
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Kamulegeya
I have a list box control i want to use to open a form

I have this code

CODE
Private Sub lstTransactions_DblClick(Cancel As Integer)
Dim strName As String
Dim lngID As Long
On Error GoTo Form_Error
If Me.lstTransactions.ItemsSelected.Count = 0 Then
MsgBox " No Transaction selected", vbExclamation
Exit Sub
End If
strName = Me.lstTransactions.Column(2)
lngID = Me.lstTransactions.Column(1)
DoCmd.OpenForm strName, acNormal, , , acFormEdit, acDialog, lngID

Form_Exit:
Exit Sub
Form_Error:
MsgBox " Error:" & Err.Description
Resume Form_Exit


End Sub



In the forms OnLoad event i have this code

CODE
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me!TransactionID = CLng(Me.OpenArgs)
End If
End Sub



When i execute the code i get an error message "Runtime error 3164, field can not be updated"

What could be the problem?


Ronald
theDBguy
Hi Ronald,

Two things:

1. Are you using a multi-select Listbox?

and

2. Is TransactionID an Autonumber field?

Just my 2 cents... 2cents.gif
Doug Steele
Is the form updatable if you open it without passing an OpenArgs parameter?
JonSmith
Right, I'm going on a hunch here but I think what you are trying to do is open a databound form and find a specific record where the TransactionID is equal to the one in your listbox (Same function as finding a record based on a listbox value but the record is on a different form this time).

Can I suggest

CODE
DoCmd.OpenForm strName, acNormal, ,"[TransactionID] = " & lngID , acFormEdit, acDialog


JonSmith
Kamulegeya
QUOTE (theDBguy @ May 28 2012, 07:17 PM) *
Hi Ronald,

Two things:

1. Are you using a multi-select Listbox?

and

2. Is TransactionID an Autonumber field?

Just my 2 cents... 2cents.gif



Hello DbGuy

1 It is not multi select

2 Yes it is an autonumber field

Ronald
Kamulegeya
QUOTE (Doug Steele @ May 28 2012, 07:17 PM) *
Is the form updatable if you open it without passing an OpenArgs parameter?


Hello Doug

It is updatable . Data edit form


Ronald
Doug Steele
You cannot assign a value to an AutoNumber field, which is what your code is trying to do.

Re-read JonSmith's suggestion. Is that what you're hoping to accomplish?
Kamulegeya
QUOTE (JonSmith @ May 28 2012, 08:08 PM) *
Right, I'm going on a hunch here but I think what you are trying to do is open a databound form and find a specific record where the TransactionID is equal to the one in your listbox (Same function as finding a record based on a listbox value but the record is on a different form this time).

Can I suggest

CODE
DoCmd.OpenForm strName, acNormal, ,"[TransactionID] = " & lngID , acFormEdit, acDialog


JonSmith



Hello Smith

This should work but...the listbox lists different forms with different IDs as primary keys..that is why i wanted to use open arguments...

May be it can not be done?

Ronald
JonSmith
Don't give up so easily! If you want to use the openargs then change your load code to

CODE
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[TransactionID] = " & CLng(Me.OpenArgs)
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Kamulegeya
QUOTE (Doug Steele @ May 28 2012, 09:26 PM) *
You cannot assign a value to an AutoNumber field, which is what your code is trying to do.

Re-read JonSmith's suggestion. Is that what you're hoping to accomplish?



Hello Doug

Smith's suggestion should work but ...the listbox displays different forms

Let me try to explain

I wanted something to display previous say 5 data entry jobs done for different activities e.g order entry , customer data entry

I added code in the after update event of the forms i want to display which captures the form name,RecordID, and Description of the activity

This code inserts this data into a temporary table to which the listbox is bound. Using a timer event , the listbox data is re queried

I wanted a way of opening the records again ...by double clicking the listbox ...

I thought that using open arguments, it might work...

Ronald
Kamulegeya
QUOTE (JonSmith @ May 28 2012, 09:35 PM) *
Don't give up so easily! If you want to use the openargs then change your load code to

CODE
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[TransactionID] = " & CLng(Me.OpenArgs)
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark



Hello Smith

This has worked!

But i think i need to tweak to handle cases when open arguments is Null?

Thank you so much

Ronald
Doug Steele
CODE
Dim rs As Object
  
  If IsNull(Me.OpenArgs) = False Then
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[TransactionID] = " & CLng(Me.OpenArgs)
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  End If


To go back to your old approach, is there some way you can add the name of the field to the list box?

CODE
Private Sub lstTransactions_DblClick(Cancel As Integer)
Dim strName As String
Dim strFieldName
Dim lngID As Long
  
On Error GoTo Form_Error
  
  If Me.lstTransactions.ItemsSelected.Count = 0 Then
    MsgBox " No Transaction selected", vbExclamation
  Else
    strName = Me.lstTransactions.Column(2)
    lngID = Me.lstTransactions.Column(1)
    strFieldName = Me.lstTransactions.Column(3)
    DoCmd.OpenForm strName, acNormal, ,"[" & strFieldName & "] = " & lngID , acFormEdit, acDialog
  End If
  
Form_Exit:
  Exit Sub
  
Form_Error:
  MsgBox " Error:" & Err.Description
  Resume Form_Exit
  
End Sub


Kamulegeya
QUOTE (Doug Steele @ May 28 2012, 11:10 PM) *
CODE
Dim rs As Object
  
  If IsNull(Me.OpenArgs) = False Then
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[TransactionID] = " & CLng(Me.OpenArgs)
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  End If


To go back to your old approach, is there some way you can add the name of the field to the list box?

CODE
Private Sub lstTransactions_DblClick(Cancel As Integer)
Dim strName As String
Dim strFieldName
Dim lngID As Long
  
On Error GoTo Form_Error
  
  If Me.lstTransactions.ItemsSelected.Count = 0 Then
    MsgBox " No Transaction selected", vbExclamation
  Else
    strName = Me.lstTransactions.Column(2)
    lngID = Me.lstTransactions.Column(1)
    strFieldName = Me.lstTransactions.Column(3)
    DoCmd.OpenForm strName, acNormal, ,"[" & strFieldName & "] = " & lngID , acFormEdit, acDialog
  End If
  
Form_Exit:
  Exit Sub
  
Form_Error:
  MsgBox " Error:" & Err.Description
  Resume Form_Exit
  
End Sub


Hello Doug

We live in different continents and time zones sorry for the late reply

your proposal worked .

To get the field name, i used an expression like

CODE
Me.ControlName.ControlSource


And since i am doing it for different forms, i developed a class module(for sake of learning them) below
CODE
'---------------------------------------------------------------------------------------
' Module    : Class1
' Author    : Admin
' Date      : 27/05/2012
' Purpose   : tracks transactions and list them on a listbox control
'---------------------------------------------------------------------------------------

Option Compare Database
Option Explicit

Public t_ID As Long   '''transactionID
Public t_Name As String   ''''TransactionName
Public frmName As String   ''''form where transaction recorded
Public fdlName As String

Private Property Get TransactionID() As Long
TransactionID = t_ID
End Property

Private Property Get TransactionName() As String
TransactionName = t_Name
End Property

Private Property Get FormName() As String
FormName = frmName
End Property
Private Property Let TransID(ID As Long)
ID = t_ID
End Property
Private Property Let TransName(myName As String)
myName = t_Name
End Property
Private Property Let frm_Name(anyName As String)
anyName = frmName
End Property

Private Property Get FieldName() As Long
FieldName = fdlName
End Property
Private Property Let myName(anyFieldName As String)
anyFieldName = fdlName
End Property


and this how i call it in one of the forms

I declared a module variable
CODE
Public t_Transactions As clsTransactions


and this is the code in one of the forms

CODE
Private Sub Form_AfterUpdate()
Dim db As dao.Database
Dim rst As dao.Recordset
Set t_Transactions = New clsTransactions
   t_Transactions.t_ID = Me.TransactionID
   t_Transactions.frmName = "frmProcessBOQS"
   t_Transactions.t_Name = Me.ContractID.Column(1) & " LBC Instructions "
   t_Transactions.fdlName = Me.ID.ControlSource
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblTempTransactions", dbOpenDynaset)
With rst
    .AddNew
    !TransactionID = t_Transactions.t_ID
    !FormName = t_Transactions.frmName
    !TransactionType = t_Transactions.t_Name
    !FieldName = t_Transactions.fdlName
    .Update
End With
   rst.Close
  Set t_Transactions = Nothing
  Set rst = Nothing
  Set db = Nothing
End Sub


theDBguy
Hi Ronald,

Glad to hear you got your solution. Good luck with your project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.