Double click on MS Access ListBox opens form to particular record but unable to edit

不打扰是莪最后的温柔 提交于 2020-06-18 05:41:06

问题


I have an Access database that has a patient admission form with a list-box that lists all the procedures that patient has had. The list-box contains ProcedureID, ProcedureDate and ProcedureTitle. The list-box is bound to 1 or procedureID.

I have a double click event for the list-box that opens the procedure form. The form has tabs subforms with various bits of data relating to the procedure.

The form opens to the correct record and displays the related data in the form and subforms. The problem is when i try to edit the data that is on the Procedure form I get the following error message..

you can't assign a value to this object

The error points to the on dirty event on my procedure form. This is only a problem if i try to edit the data in the parent form, the subforms work fine and any edits are accepted.

I have this code in the double click event in the list-box

Private Sub lst_Procedure_DblClick(Cancel As Integer)

  'double click to open procedure form to the selected record

  Dim ProcID As Long

  ProcID = Me!lst_Procedure

  DoCmd.Close acForm, "frm_Admission"
  DoCmd.OpenForm "frm_Procedure", , , "[ProcedureID] = " & ProcID

End Sub

and this code on the procedure form to open to the correct record

Private Sub Form_Dirty(Cancel As Integer)

  'open Procedure form to record selected in procedure list
   Me.ProcedureID = Me.OpenArgs

End Sub

Any suggestions would be greatly appreciated. I've tried receiving the openargs in onLoad instead of onDirty but to no avail.


回答1:


DoCmd.OpenForm "frm_Procedure", , , "[ProcedureID] = " & ProcID

opens the form with an existing record. You are using the WhereCondition parameter of OpenForm. https://msdn.microsoft.com/en-us/library/office/ff820845.aspx

So there is no need to set Me.ProcedureID in the opened form. Just remove the Dirty event procedure.

I guess that ProcedureID is the primary key and an AutoNumber?
AutoNumber values cannot be changed.



来源:https://stackoverflow.com/questions/41562173/double-click-on-ms-access-listbox-opens-form-to-particular-record-but-unable-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!