我知道有几个问题,但我已经看了几行这段代码,无法弄清楚问题。它一直说这行代码存在语法错误,我看不到它。任何帮助,将不胜感激。感谢。
db.Execute "UPDATE Questions SET Date = #4/26/2014#,TwoChapt=False " & _
" WHERE Book = '" & rs!Book & "' AND Chapter = '" & _
rs!Chapter & "' AND QuestionType = 1 "
答案 0 :(得分:1)
使用querydefs考虑parameterized queries并避免在字符串中插值:
SQL (另存为存储的Access查询对象)
PARAMETERS BookParam Text(255), ChapterParam Text(255);
UPDATE Questions
SET [Date] = #4/26/2014#, TwoChapt = False
WHERE Book = [BookParam] AND Chapter = [ChapterParam] AND QuestionType = 1;
VBA (放置在记录集循环中,Dim
和Set ... = Nothing
除外)
...
Dim qdef As Querydef
Set qdef = Currentdb.Querydefs("MyStoredQuery")
Do While ...
' BIND PARAMS
qdef!BookParam = rs!Book
qdef!ChapterParam = rs!Chapter
' EXECUTE ACTION
qdef.Execute, dbFailOnError
Loop
Set qdef = Nothing