在Access VBA中,我想使用"设置"表中的值,而不是代码中的硬编码文件夹位置等.我无法弄清楚如何从表中加载一个值并在代码中使用它.
Dim oFSystem As Object
Dim oFolder As Object
Dim oFile As Object
Dim sFolderPath As String
sFolderPath = "C:\Documents and Settings\Main\Desktop\Files" 'BAD BAD, I WANT TO AVOID THIS
Run Code Online (Sandbox Code Playgroud)
我创建了一个表" 设置 ",我想使用该值
SELECT TOP 1 Settings.SettingsValue FROM Settings WHERE (((Settings.SettingName)="Files Folder Location"));
Run Code Online (Sandbox Code Playgroud)
如果只有一条记录,其中SettingName ="Files Folder Location",则可以使用DLookup功能.
sFolderPath = DLookup("SettingsValue", "Settings", "SettingName=""Files Folder Location""")
Run Code Online (Sandbox Code Playgroud)