代码之家  ›  专栏  ›  技术社区  ›  Curtis Inderwiesche

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

  •  2
  • Curtis Inderwiesche  · 技术社区  · 17 年前

    我正在尝试使用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
    
    2 回复  |  直到 9 年前
        1
  •  4
  •   DJ.    17 年前

    这将保存查询defs

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

    那么LoadFromText应该可以工作了

        2
  •  4
  •   Curtis Inderwiesche    17 年前

    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
    end if
    

    显然,需要补充的是:

      Const acQuery = 1
    

    感谢DJ

    推荐文章