2016-03-31 14 views
0

ください、私は助けが必要です、エクスポートするときにこのエラーが発生しました。 = SQL &その後 SQL」、のPhoneNumber、Microsoft Accessランタイムエラー '3075'クエリ式

SQL = SQL & "グループ化ContactID、TitleID、担当者名、SuffixID、会社、JobTitle、Email1、EMAIL2、Email3、WebPageAddress、IMAddress" Me.chkExportPhone = Trueの場合PhoneNumberType " END IF もしMe.chkExportAddress = trueの場合、 「SQL = SQL & "住所1、住所2、市、州、郵便番号、AddressTypeに" SQL = SQL &"、住所1 PostalSuburb、などAddressLine3などのPostalAddress、住所2など住所、郊外、都道府県、郵便番号、郵便番号としての住所、住所タイプ " 終了の場合

sql = sql & " , Classification, ClassificationCopy,ReferenceNumber, InvoiceComments,AccountComments,Status,LastContactDate,Notes " 

クエリ定義 設定qryDef = CurrentDb.QueryDefs( "qryContactExport") qryDef.sql = SQL 設定qryDef =何も 「DoCmd.TransferSpreadsheet acExport、acSpreadsheetTypeExcel9、 "qryContactExport"、 "として暗いqryDef C:\一時\のTemp.xls」 DoCmd.OutputTo acOutputQuery、 "qryContactExport"、acFormatXLS、Application.CurrentProject.Path & "\ Temp.xls"、真の End Subの

Visual Basicは、エラーがこれですと言っていますqryDef.s ql = sql。

ありがとう!

+0

qryDef.sql = sql行の直前のsql変数にはどのような値が入りますか?私はその価値があなたに何が問題なのかをたくさん伝えると思う。コードをデバッグして変数を調べることで、値を取得できます。また、Stackoverflowへようこそ - あなたの質問を編集して、現在読んでいることはほとんど不可能なので、書式を修正してください。 – user2316154

+0

回答ありがとうございます。これは値 の場合Me.chkExportAddress = True then 'sql = sql& "、AddressLine1、AddressLine2、City、State、Zip、AddressType" sql = sql& "、AddressLine1をPostalAddress、AddressLine2エラーが言う –

+0

、分類、ClassificationCopy、ReferenceNumber、InvoiceComments、AccountComments、ステータス、LastContactDate、ノート " " = SQL SQL&もし終了 " 郵便番号、AddressTypeになどPostalSuburb、AddressLine3 StreetAddressとして、市郊外など、州、郵便番号などクエリ式 'AddressLine1 as PostalAddress'の構文エラー(演算子がありません) –

答えて

0

さて、私は(それはで動作するようにちょうどこの小さなスニペットを伝えるのは難しいの一種である。)これは問題だと思う

がダウンして1行マークの単一引用符を移動:

sql = sql & " Group By ContactID, TitleID, ContactName, SuffixID, Company, JobTitle, Email1, Email2, Email3, WebPageAddress, IMAddress" 
If Me.chkExportPhone = True Then 
    sql = sql & " , PhoneNumber, PhoneNumberType " 
End If 
If Me.chkExportAddress = True Then 
**'**  sql = sql & " , AddressLine1, AddressLine2, City, State, Zip, AddressType " 
    sql = sql & " , AddressLine1 as PostalAddress, AddressLine2 as PostalSuburb,AddressLine3 as StreetAddress, City as Suburb, State, Zip as PostalCode, AddressType " 
End If 

sql = sql & " , Classification, ClassificationCopy,ReferenceNumber, InvoiceComments,AccountComments,Status,LastContactDate,Notes " 

sql = sql & " Group By ContactID, TitleID, ContactName, SuffixID, Company, JobTitle, Email1, Email2, Email3, WebPageAddress, IMAddress" 
If Me.chkExportPhone = True Then 
    sql = sql & " , PhoneNumber, PhoneNumberType " 
End If 
If Me.chkExportAddress = True Then 
     sql = sql & " , AddressLine1, AddressLine2, City, State, Zip, AddressType " 
    ' sql = sql & " , AddressLine1 as PostalAddress, AddressLine2 as PostalSuburb,AddressLine3 as StreetAddress, City as Suburb, State, Zip as PostalCode, AddressType " 
End If 

sql = sql & " , Classification, ClassificationCopy,ReferenceNumber, InvoiceComments,AccountComments,Status,LastContactDate,Notes " 

にこれは間違った行をコメントアウトし、良いものに置き換えられます。 GROUP BYステートメントのASキーワードが問題を引き起こしています。

+0

ありがとうございます!実行時 '3122' 指定された式 'StreetAddress'を集計関数の一部として含まないクエリを実行しようとしました。 Visual Basicのショー、私のエラー DoCmd.OutputTo acOutputQuery、 "qryContactExport"、acFormatXLSのように、このラインは、Application.CurrentProject.Path& "\のTemp.xls"、真の –

+0

は今完璧です、どうもありがとう、私はちょうど追加sql = sql& "、AddressLine1、AddressLine2、City、State、Zip、AddressType"のAddressLine3。 ありがとうございます。 –

0
 
sql = sql & " Group By ContactID, TitleID, ContactName, SuffixID, Company, JobTitle, Email1, Email2, Email3, WebPageAddress, IMAddress" 
    If Me.chkExportPhone = True Then 
     sql = sql & " , PhoneNumber, PhoneNumberType " 
    End If 
    If Me.chkExportAddress = True Then 
'  sql = sql & " , AddressLine1, AddressLine2, City, State, Zip, AddressType " 
     sql = sql & " , AddressLine1 as PostalAddress, AddressLine2 as PostalSuburb,AddressLine3 as StreetAddress, City as Suburb, State, Zip as PostalCode, AddressType " 
    End If 

    sql = sql & " , Classification, ClassificationCopy,ReferenceNumber, InvoiceComments,AccountComments,Status,LastContactDate,Notes " 

Dim qryDef As QueryDef 
    Set qryDef = CurrentDb.QueryDefs("qryContactExport") 
    qryDef.sql = sql 
    Set qryDef = Nothing 
    'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryContactExport", "C:\Temp\Temp.xls" 
    DoCmd.OutputTo acOutputQuery, "qryContactExport", acFormatXLS, Application.CurrentProject.Path & "\Temp.xls", True 
End Sub 
関連する問題