拜托,我需要帮助,当我尝试导出时发生了这个错误。
sql = sql& "按联系人ID,TitleID,ContactName,SuffixID,公司,JobTitle,Email1,Email2,Email3,WebPageAddress,IMAddress" 如果Me.chkExportPhone = True那么 sql = sql& " ,PhoneNumber,PhoneNumberType" 万一 如果Me.chkExportAddress = True那么 ' sql = sql& " ,AddressLine1,AddressLine2,City,State,Zip,AddressType" sql = sql& " ,AddressLine1为PostalAddress,AddressLine2为PostalSuburb,AddressLine3为StreetAddress,City为郊区,State,Zip为PostalCode,AddressType" 结束如果
sql = sql & " , Classification, ClassificationCopy,ReferenceNumber, InvoiceComments,AccountComments,Status,LastContactDate,Notes "
Dim qryDef作为QueryDef 设置qryDef = CurrentDb.QueryDefs(" qryContactExport") qryDef.sql = sql 设置qryDef = Nothing ' DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel9," qryContactExport"," C:\ Temp \ Temp.xls" DoCmd.OutputTo acOutputQuery," qryContactExport",acFormatXLS,Application.CurrentProject.Path& " \ Temp.xls",True 结束子
Visual Basic说错误就是这行qryDef.sql = sql。
非常感谢!
答案 0 :(得分: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
答案 1 :(得分: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 "
到
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关键字导致了问题。