访问VBA查找文件夹并创建(如果不存在)DLOOKUP [英] Access VBA lookup folder and create if does not exist DLOOKUP
问题描述
我正在使用Access 2010构建一个小程序,并使用以下方法检查文件夹,如果该文件夹不存在,则创建它,该方法可以正常工作:
I'm building a small program using Access 2010 and am using the below to check for a folder and if it doesn't exist, then create it, which works:
'need code to create folder
If Dir("C:\Michael\Test", vbDirectory) = "" Then
MkDir ("C:\Michael\Test")
Else
'do nothing for directory already exists
End If
但是,我需要对此进行修改.路径可以根据用户选择的内容而改变.目前,路径已建立并保存在字段("FlatFile")中的表("tmpDestFolders")中.
However, I need to modify this. The path can change depending on what the user has selected. At the moment the path is built up and saved in a table ("tmpDestFolders") in field ("FlatFile").
实际上,我需要查找此值,但以下内容不起作用-如何更改它,以便它将检查字段值是多少?我只是不断收到错误76无效路径:
In effect, I need to lookup whatever this value is, but the below does not work - how can I changed it so it will check what ever the field value is? I just keep receiving error 76 invalid path:
'need code to create folder
If Dir(DLookup("FlatFile", "tmpDestFolders"), vbDirectory) = "" Then
MkDir (DLookup("FlatFile", "tmpDestFolders"))
Else
'do nothing for directory already exists
End If
推荐答案
使用API调用:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
,然后简单地:
MakeSureDirectoryPathExists DLookup("FlatFile", "tmpDestFolders")
这篇关于访问VBA查找文件夹并创建(如果不存在)DLOOKUP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!