【问题标题】:How can set "Shift + Click" on VBA Access?如何在 VBA Access 上设置“Shift + Click”?
【发布时间】:2014-05-20 20:16:17
【问题描述】:

我想通过“Shift+Click”(Shift键+鼠标左键单击)在文本字段上设置一个Open FileDialog,怎么可能?

我为打开文件对话框写了这个:

Private Sub Article_Click()
    Dim dialog As FileDialog
    Set dialog = Application.FileDialog(msoFileDialogFilePicker)
    With dialog
    .AllowMultiSelect = False
    .Show
    Me.Article() = .SelectedItems(1)
    End With 
End Sub

【问题讨论】:

标签: ms-access vba


【解决方案1】:

您可以使用文本框的MouseDown 事件来确定 ShiftCtrlAlt 键的状态这里描述的技术:

Detecting SHIFT, CTRL, and ALT States

在你的情况下,如果你只关心 Shift 键,那么你可以使用这样的东西:

Option Compare Database
Option Explicit

Dim ShiftTest As Integer

Private Sub Article_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   ShiftTest = Shift And 1
End Sub

Private Sub Article_Click()
    If ShiftTest = 1 Then
        Dim dialog As FileDialog
        Set dialog = Application.FileDialog(msoFileDialogFilePicker)
        With dialog
            .AllowMultiSelect = False
            .Show
            Me.Article() = .SelectedItems(1)
        End With 
    End If
End Sub

【讨论】:

    猜你喜欢
    • 2012-03-30
    • 1970-01-01
    • 2019-09-04
    • 2015-07-16
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    相关资源
    最近更新 更多