4

情况: 我有一个 Access 2010 数据库,打算部署在 Windows 8 平板电脑上。应用程序的主窗体包含一个 Treeview 控件。在 Treeview 上选择一个节点会设置用于查看/编辑所选节点项的详细信息的多个子表单之一的可见性。每个子表单的更新前事件都有一个是/否消息框和一些基本代码。因此,当子窗体上的记录是脏的并且用户单击主窗体上的任何位置(包括 Treeview 控件中的任何位置)时,都会触发此代码。

问题: 当子表单记录脏并且用户在Treeview控件上的任意位置点击时,会弹出消息框但由于应用程序繁忙而无法与之交互。做什么,我不知道,但它会一直保持这种状态,直到通过任务管理器关闭 Access。除了 Click 事件之外,没有任何代码附加到 Treeview。即使它们在现有节点下方的 Treeview 中触摸空白区域,也会发生这种情况。

如果记录不脏,一切正常。

如果记录是脏的并且用户点击了子窗体上的“保存”按钮来触发更新前事件,那么一切正常。

如果用户点击不同的控件或在主窗体上的空白处,将触发 BeforeUpdate 事件并且一切正常。

如果您将鼠标插入平板电脑并通过单击而不是点击来执行相同的一系列步骤,则一切正常。

我已经进行了大量搜索,但无法找到与此相关的任何内容,因此任何建议或对新地方寻找建议的指导将不胜感激。

我附上了每个子窗体中存在的更新前代码示例。这是非常基本的,但也许其中有些东西是点击和 Treeviews 不喜欢的。

Private Sub Form_BeforeUpdate(Cancel As Integer)
'If the form data has changed a message is shown asking if
'the changes should be saved. If the answer is no then
'the changes are undone

 On Error GoTo BeforeUpdate_Error

If Me.Dirty Then
'Add PropertyID, LPParentNodeID and TreeNodeID if Record is new

    If Me.NewRecord Then
        Me.PropertyID = Me.Parent!PropertyID
        Me.LPParentNodeID = Me.Parent!txtCurrKey
        Me.TreeNodeID = DateDiff("s", Date, Now())
    End If


'Display prompt to save the record
  If MsgBox("The record has changed - do you want to save it?", _
  vbYesNo + vbQuestion, "Save Changes") = vbNo Then
     Me.Undo
  End If
End If

'If the record is still dirty, then record the change in the Audit table
If Me.Dirty Then
    Call AuditTrail(Me, InstanceID, PropertyID)
End If


BeforeUpdate_Exit:
   Exit Sub

BeforeUpdate_Error:
   MsgBox Err.Description
   Resume BeforeUpdate_Exit
End Sub

2013 年 8 月 30 日补充:我忘了在原始问题中提及调试行为。当我在从实际 Sub 入口点到带有消息框的 If 语句的任何行上的子窗体的 BeforeUpdate Sub 上设置断点时,会出现代码窗口,但应用程序再次变得繁忙,我无法与之交互任一窗口。就像以前一样,这种行为是点击那个该死的 Treeview 控件所独有的。

4

1 回答 1

1

您可以做的是在每个子窗体中添加一种编辑/保存结构,从而在单击编辑之前锁定子窗体中的控件,并在单击保存后重新锁定。所以:

private sub bEdit()
    editMode true
end sub
private sub bSave()
    ...save logic
    editMode false
end sub
private sub editMode(isEdit as boolean)
    dim ctl as control
    for each ctl in me.controls
        if ctl.controltype is actextbox or ctl.controltype is accombobox then
            ctl.locked = (not isEdit)
        end if
    next
end sub

使用这种方法,通过添加为父窗体添加编辑模式控件是一项小任务

me.parent.editmode isEdit

到 editmode 过程结束。

在父窗体中,editMode 需要是一个 PUBLIC 子窗体。

在这个子中,控制点击时树是否会做任何事情:

public sub editMode(isEdit as boolean)
    tree.enabled = (not isEdit)
end sub
于 2013-11-06T03:06:46.027 回答