2014-10-07 70 views
1

我在Access 2003Access查詢得到錯誤3141

我試圖創建一個查詢,將創建一個表已在我的excel表格必須在正確的格式工作。我想這會節省我花了很長時間而不是創建表格,然後編寫代碼來插入值,偏移單元格,插入更多等,所有這些都在一個巨大的循環中。這樣我按照需要的方式創建表格,然後將其轉儲爲excel。

我得到的問題是下面的查詢得到以下錯誤:

運行時錯誤「3141」; SELECT語句包含拼寫錯誤或缺失的保留字或參數名稱,或標點符號不正確。

DoCmd.RunSQL ("SELECT [Main Employee Table].SSN, [Main Employee Table].[LastName] AS [Last Name], [Main Employee Table].[FirstName] AS [First Name], " _ 
     & "[Main Employee Table].[MiddleName] AS [Middle Intial], " _ 
     & "[Address Table].[Address] AS [Address Line 1], Null AS [Address Line 2] [City] AS Ciity, " _ 
     & "UCase([State]) AS Sstate, Format([ZipCode],""00000"") AS [Zip Code], Null AS TaxState, " _ 
     & """20141201"" AS [Chk Request Date], [Main Employee Table].DOB AS [Date of Birth], " _ 
     & "IIf(([Status]='Beneficiary' Or [Status]='Beneficiary/late'),""05"",IIf([Status]='QDRO/TV',""01"",""00"")) AS RelationshipCode, " _ 
     & "Null AS [Lump Sum Benefit L], tblLSWindow.LSRollOver AS [Rollover Benefit R], " _ 
     & "Null AS [Partial Benefit P], Null AS [Hardship Benefit H], Null AS [Min Req Distr Benefit M], Null AS [Nontaxable Benefit], " _ 
     & "tblLSWindow.LSRollOver AS [Total], ""R"" AS [Distribution Suffix], Null AS [Marital Status], " _ 
     & """1"" AS [Federal Withholding Switch], ""1"" AS [State Withholding Switch], Null AS [Federal Exemp Number], ""0"" AS [Federal Additional Amount], " _ 
     & "Null AS [State Exemp Number], ""0"" AS [State Additional Amount], ""G"" AS [Distribution Code], " _ 
     & "[RollOverInstitution] AS [Rollover Institution Name Address Line 1], [FirstName] & "" "" & [Last Name] AS [FBO Address Line 2], " _ 
     & "[Address] AS [Rollover Institution Address Line 3], [City] AS [Rollover Institution City], [State] AS [Rollover Institution State], " _ 
     & "[ZipCode] AS [Rollover Institution Zip Code] " _ 
     & "INTO AutoCashLoadReport " _ 
     & "FROM ([Main Employee Table] LEFT JOIN tblLSWindow " _ 
     & "ON [Main Employee Table].SSN = tblLSWindow.SSN) " _ 
     & "LEFT JOIN [Address Table] ON [Main Employee Table].SSN = [Address Table].SSN " _ 
     & "WHERE ((tblLSWindow.LSRollOver>0) AND ([tblLSWindow].[IGOChk]=-1))") 

現在我意識到,這是很不禮貌的使用表,在他們的空間,但是這是一個非常古老的數據庫,我還沒有想進去惹它。

我一直無法弄清楚這段代碼有什麼問題。我一直在尋找丟失的逗號,或者我忘記關閉的括號等,但是我沒有找到任何運氣。我最初有一些常量項目(像「1」或「G」等項目),用單引號括起來,但我把它們改爲兩個雙引號,認爲它可能是問題。

任何幫助將非常感激。

+0

缺少,使用一些格式將使此一百萬時更容易閱讀。您在兩列之間缺少逗號。無AS [地址欄2] [城市] AS Ciity, – 2014-10-07 18:49:50

回答

1

您在下面的線

Null AS [Address Line 2] [City] AS Ciity 
         <--Here 
+0

就是這樣。我不相信我沒有找到那個。感謝您的幫助! – JohnT 2014-10-07 19:57:19