2015-02-05 89 views
-2

我正在使表格在表格中插入記錄。我無法運行此查詢,因爲它向我顯示語法錯誤。我嘗試了很多,但無法找到錯誤。我的查詢如下。MS Access的SQL查詢中的語法錯誤

CurrentDb.Execute " 
    INSERT into Database2Sample(
     nyu_id, location1, location2, 
     first_name, middle_name, last_name, 
     full_name, instructor_sis_id, instructor_email, 
     intstructor_net_id, personal_email, CV_link, 
     employee_nyu_global_site, highest_degree, degree_subject_area, 
     degree_status, degree_granting_institution, accomplishments, 
     Other_employee, WSQ_home_campus, teaching_language_course) 
    VALUES 
    ('" & Me.nyu_id & "', '" 
     & Me.location1 & "', '" 
     & Me.location2 & "', '" 
     & Me.first_name & "', '" 
     & Me.middle_name & "', '" 
     & Me.last_name & "', '" 
     & Me.full_name & "', '" 
     & Me.instructor_sis_id & "', '" 
     & Me.instructor_email & "', '" 
     & Me.intstructor_net_id & "', '" 
     & Me.personal_email & "', '" 
     & Me.CV_link & "', '" 
     & Me.employee_nyu_global_site & "', '" 
     & Me.highest_degree & "', '" 
     & Me.degree_subject_area & "', '" 
     & Me.degree_status & "', '" 
     & Me.degree_granting_institution & "', '" 
     & Me.accomplishments & "', , '" 
     & Me.Other_employee & "', '" 
     & Me.WSQ_home_campus & "', '" 
     & Me.teaching_language_course & "')" 

Error text

+0

現在您的問題格式正確了,您應該返回並添加比您的少於通知的錯誤對話框更多的圖片。您需要添加錯誤日誌或有關錯誤的詳細信息,以及您所做的除了在問題上發表微弱嘗試之外的其他信息。 – apesa 2015-02-05 20:47:04

+0

我建議首先將insert語句保存到字符串中,然後將字符串輸出到消息框窗口,然後通過查詢窗口排除故障。我會猜測你有一個缺失',一個數據類型轉換問題,或一個字段丟失的值,反之亦然。但要格式化上面的SQL是有點痛苦的。是21場,22個值。 – xQbert 2015-02-05 20:47:26

回答

2

你有成就和員工的場之間的值,兩個逗號。

'" & Me.accomplishments & "', , '" & Me.Other_employee & "' 

刪除它們中的任何一個都會使它工作。

+0

假設他們沒有忘記一個字段而不是一個額外的值,並且超出它的數據類型對應於值中的數據類型,或者隱式轉換將會發生......我同意這是問題出在哪裏,但我不知道是否簡單地刪除逗號就能解決問題。 (雖然任何好開始) – xQbert 2015-02-05 20:52:30

+0

謝謝你衝。爲我找到一個錯誤真是很乏味。我感謝您的幫助。 – Nandish 2015-02-05 20:54:31

+0

在這種情況下,我認爲在列名部分保留空白將起作用。無論如何,最好的做法是逐個構建循環中的值。 – 2015-02-05 20:56:33