我的代码(MS Access VBA)有一个小问题。没什么大不了的,但是在取消请求中不应该看到。
代码的初始部分使我能够提取出效果很好的图像的路径和文件名。
Private Sub Image2_DblClick(Cancel As Integer)
'Source: http://stackoverflow.com/questions/14915179/ms-access-browse-for-file-and-get-file-name-and-path
Dim f As Object
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant
Set f = Application.FileDialog(3)
f.AllowMultiSelect = False
If f.Show Then
For Each varItem In f.SelectedItems
strFile = Dir(varItem)
strFolder = Left(varItem, Len(varItem) - Len(strFile))
TempVars.Add "imagePath2", strFolder & strFile
Next
End If
Set f = Nothing
下一部分将该字符串插入查询中的指定字段。这也很漂亮。
With DoCmd
.SetWarnings False
.OpenQuery "updateQueryVarietiesImage2"
.SetWarnings True
DoCmd.RunCommand acCmdRefresh
Me.Requery
End With
End Sub
我遇到的问题是,如果我取消从生成的 pop 窗口中选择图像。取消后,我得到“运行时错误'3464':条件表达式中的数据类型不匹配”
单击“调试”突出显示
.OpenQuery "updateQueryVarietiesImage2"
我确定该错误与以下事实有关:由于取消而导致查询未运行,但我不希望该错误出现。如果用户单击“取消”,我应该使用什么代码阻止错误出现?
最佳答案
如果未选择任何文件,您能否跳过代码:
If f.SelectedItems.Count > 0 Then
With DoCmd
.SetWarnings False
.OpenQuery "updateQueryVarietiesImage2"
.SetWarnings True
.RunCommand acCmdRefresh
End With
Me.Requery
End If
关于vba - 停止带有取消请求的代码时如何删除运行时错误 '3464',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41417973/