2009-05-13 28 views
2

VBScriptを使用してテキストファイル、クエリをMS Accessクエリコレクションに読み込もうとしています。私はこのようなものを使用しています: コードはHereに由来しています。MS AccessクエリのApplication.LoadFromTextの代わりに

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を使用してクエリ定義を作成する方法は不明です。

アイデア?

注:その後LoadFromTextちょうど完全に私のために

答えて

4

: は、私はもともとこのようなものを使用してファイルにエクスポート私のソリューションを追加したい。

どうやら
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 

だっ追加させるのに必要なすべて:DJ

まれ
+2

のConst acQuery = 1 –

+1

Const acQuery = 1 

おかげで、あなたが入力テーブルとしてサブクエリを持つクエリを持っている場合LoadFromTextは機能しますが、壊れたクエリが作成されます。エクスポートされたクエリtxtファイル内には、 "Begin InputTables"というセクションがあり、 "Name"テーブルのテーブルがサブクエリのSQLになります。インポート後、accessはこの名前をquerydef名として解釈します。この問題を回避するには、クエリのエクスポートファイルを解析し、サブクエリを検索し、エクスポート処理中にサブクエリを「アンパック」します。アクセスオブジェクトから破損したバイナリブロックを削除した自動修正ルーチンを作成しなければならなかったので、これに遭遇しました。 – DHW

3

を動作するはずです。これは、クエリDEFSに

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

を保存し

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