MS Access 2013 VBA-目录路径中的句点(“。”)问题

时间:2018-08-30 21:52:18

标签: sql vba ms-access-2013

我有一些代码可以从主mdb文件更新一系列mdb文件。该代码从主服务器中的表中提取目录地址。但是,某些目录名称包含句点。这将产生错误“运行时错误3126,名称K:\ DRUMSFILES \ CARDINALLÉGERJR。HIGH SCHOOL \ JOB1_SJ3911-SS \ DATA \ students] .mdb的无效包围”

“ JR”中的句点。导致错误。我无法控制目录名称。

我尝试使用双引号和方括号,但是没有找到有效的组合。

代码如下所示:

Dim sqlStr As String
Dim db As dao.Database
Dim rs As dao.Recordset

sqlStr = "SELECT SchoolFilePath from Jobs;"

Set db = CurrentDb
Set rs = db.OpenRecordset(sqlStr)

rs.MoveFirst
DoCmd.SetWarnings (WarningsOff)
Do While Not rs.EOF
  filePath = rs.Fields("SchoolFilePath") & "\students.mdb"
  strSQL = "DELETE FROM AddItems IN '" & filePath & "';"
  CurrentProject.Connection.Execute strSQL
  sqlStr = "insert into AddItems (Item1, Item2, Item3) IN '" & filePath & "' VALUES ('Retouch', 'Problem Orders', 'Class Photo/Memory Book');"
  Debug.Print sqlStr
  DoCmd.RunSQL (sqlStr)
  rs.MoveNext
Loop
DoCmd.SetWarnings (WarningsOn)

调试行显示SQL行的外观。最后一个错误:

    insert into AddItems (Item1, Item2, Item3) IN 'K:\DRUMSFILES\CAMILLA SCHOOL\JOB1_MD3907 - 2PMB\DATA\students.mdb' VALUES ('Retouch', 'Problem Orders', 'Class Photo/Memory Book');
    insert into UserFields (User1, User2, User3) IN 'K:\DRUMSFILES\CAMILLA SCHOOL\JOB1_MD3907 - 2PMB\DATA\students.mdb' VALUES ('Problem Order', 'Family Plan', 'Late/Reorder');
    insert into AddItems (Item1, Item2, Item3) IN 'K:\DRUMSFILES\CAMILLA SCHOOL\JOB2_MD3907 - 1 - 2PMB - RTK\DATA\students.mdb' VALUES ('Retouch', 'Problem Orders', 'Class Photo/Memory Book');
    insert into AddItems (Item1, Item2, Item3) IN 'K:\DRUMSFILES\CARDINAL LÉGER JR. HIGH SCHOOL\JOB1_SJ3911 - SS\DATA\students.mdb' VALUES ('Retouch', 'Problem Orders', 'Class Photo/Memory Book');

0 个答案:

没有答案