2014-03-29 63 views
1

我想更新serial.Issuedate從窗體中獲取,但它給出的語法錯誤。 請幫我解決這個錯誤。 我的代碼如下:日期不通過vba中的sql代碼更新

Private Sub Command30_Click() 

Set serialrs = CurrentDb.OpenRecordset("serial") 
Dim Idate As Date 
Dim Itodo As String 
Idate = Me.IssuedDate.Value 
Itodo = Me.IssuedToDO.Value 

Dim issueqry As String 
issueqry = "UPDATE serial " _ 
& " set serial.IssueToDO = '" & Itodo & "'" _ 
& " serial.issuedate = (#" & Format(Idate, "mm\/dd\/yyyy") & "#)" _ 
& " WHERE (((serial.id) Between 1 And 10)) " 

DoCmd.RunSQL issueqry 

MsgBox ("Issued Done") 

End Sub 
+0

我對VBA不夠了解,但'Format'函數可能不需要'\ /'。你可能會寫'Format(Idate,「mm/dd/yyyy」)'' – zedfoxus

回答

1

當您更新多個字段,你必須包括字段表達式這樣之間的逗號...

SET [field name] = "foo", [another field] = 17 
         ^
         here 

因此,嘗試這樣的代碼...

issueqry = "UPDATE serial " _ 
& " set serial.IssueToDO = '" & Itodo & "'," _ 
& " serial.issuedate = #" & Format(Idate, "mm/dd/yyyy") & "#" _ 
& " WHERE serial.id Between 1 And 10" 

也給自己一個機會來檢查代碼生成字符串...

Debug.Print issueqry 

您可以在立即窗口中查看Debug.Print的輸出。 Ctrl + g會帶你去那裏。