双击 MS Access ListBox 打开表单到特定记录但无法编辑 [英] Double click on MS Access ListBox opens form to particular record but unable to edit

查看:49
本文介绍了双击 MS Access ListBox 打开表单到特定记录但无法编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Access 数据库,其中有一个患者入院表,其中有一个列表框,其中列出了患者进行的所有手术.列表框包含ProcedureID、ProcedureDate 和ProcedureTitle.列表框绑定到 1 或 procedureID.

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

任何建议将不胜感激.我试过在 onLoad 而不是 onDirty 中接收 openargs 但无济于事.

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

推荐答案

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

用现有记录打开表单.您正在使用 OpenFormWhereCondition 参数.https://msdn.microsoft.com/en-us/library/office/ff820845.aspx

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

所以不需要在打开的表单中设置Me.ProcedureID.只需删除 Dirty 事件过程.

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

我猜 ProcedureID 是主键和自动编号?
无法更改自动编号值.

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

这篇关于双击 MS Access ListBox 打开表单到特定记录但无法编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆