ms-access - MS Access 查询的 Application.LoadFromText 的替代方案

标签 ms-access vba vbscript

我正在尝试使用 VBScript 从文本文件加载查询到 MS Access 查询集合。我正在使用这样的东西: 代码源自Here .

 for each myFile in folder.Files
    objecttype = fso.GetExtensionName(myFile.Name)
    objectname = fso.GetBaseName(myFile.Name)
    WScript.Echo "  " & objectname & " (" & objecttype & ")"

    if (objecttype = "form") then
        oApplication.LoadFromText acForm, objectname, myFile.Path
    elseif (objecttype = "bas") then
        oApplication.LoadFromText acModule, objectname, myFile.Path
    elseif (objecttype = "mac") then
        oApplication.LoadFromText acMacro, objectname, myFile.Path
    elseif (objecttype = "report") then
        oApplication.LoadFromText acReport, objectname, myFile.Path
    elseif (objecttype = "sql") then
        'oApplication.LoadFromText acQuery, objectname, myFile.Path
        ' Add create querydef code here
    end if

 next

但我不确定如何使用 VBScript 创建查询定义。

有什么想法吗?

注意: 我最初使用这样的方式导出到文件:

For Each myObj In oApplication.CurrentDb.QueryDefs 
   Set f = fso.CreateTextFile(sExportpath & "\" & myObj.Name & ".sql", True) 
   f.WriteLine(myObj.SQL) 
   f.Close 
Next

最佳答案

这将保存查询定义

For i = 0 To db.QueryDefs.Count - 1
    Application.SaveAsText acQuery, db.QueryDefs(i).Name, sExportpath & "\" & db.QueryDefs(i).Name & ".sql"
Next i

然后 LoadFromText 应该工作

关于ms-access - MS Access 查询的 Application.LoadFromText 的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/859530/

相关文章:

sql - 从众多 Excel 文件中提取到一个数据表或文件

ms-access - 浏览文件按钮另存为 Access 中的超链接

ms-access - MS Access 更改多列

VBA - 捕获所有错误并返回描述。是否可以?

dom - 如何在 XML 文件中添加换行符?

sql-server - 无法从Access导入数据到MS SQL Server

python - VBA背面运行Python的权限错误

vba - 将 ADO 记录集文本字段排序为数字

xml - 在 VBScript 中解析 XML 字符串

excel - 如何使用VBScript有效刷新多个Excel电子表格的外部数据?