vba - TreeView 在点击时与点击时的行为不同

标签 vba ms-access treeview touch ms-access-2010

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

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

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

如果记录是脏的并且用户点击子表单上的“保存”按钮来触发 BeforeUpdate 事件,则一切正常。

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

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

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

我附上了存在于每个这些子表单上的 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

08/30/2013 补充:我忘了在原始问题中提到调试行为。当我在从实际 Sub 入口点到带有消息框的 If 语句的任何行上的子窗体的 BeforeUpdate Sub 上设置断点时,代码窗口出现但应用程序再次变得忙碌,我无法与任一窗口。就像以前一样,这种行为对于点击该诅咒的 Treeview 控件来说是独一无二的。

最佳答案

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

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 需要是一个 PUBLIC 子窗体。

在这个子中,控制点击时树是否会做任何事情:
public sub editMode(isEdit as boolean)
    tree.enabled = (not isEdit)
end sub

关于vba - TreeView 在点击时与点击时的行为不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18521090/

相关文章:

vba - Excel VBA onkey 宏可在另一个宏运行时工作

excel - 带有 if/and/or 语句的 For 循环

jquery - MVC 中最好使用的 Treeview jquery 插件是什么?

database-design - Ms-Access:任何对可变长度文本字段的小尺寸需求

ms-access - 网站使用的MS Access DB

c# - 如何打破每个项目,但不是完整的根?

c# - 为什么我会收到此消息 : "items collection must be empty before using itemssource" in a treeview?

在 Mac 上使用 Excel VBA 进行正则表达式

vba - Excel 选项卡工作表名称与 Visual Basic 工作表名称

java - 在java中从ms access数据库中检索图像