2016-03-31 3 views
0

Bitte, ich brauche Hilfe, dieser Fehler ist aufgetreten, wenn ich versuche, zu exportieren.Microsoft Access Laufzeitfehler '3075' im Abfrageausdruck

sql = sql & "Gruppieren nach ContactID, TitleID, Contact SuffixID, Unternehmen, Jobtitel, Email1, Email2, Email3, WebPageAddress, IMAddress" Wenn Me.chkExportPhone = True Then sql = sql & ", Phone, PhoneNumberType " End If Wenn Me.chkExportAddress = True Then 'sql = sql & " AddressLine1, AddressLine2, Stadt, Bundesland, Postleitzahl, Address" sql = sql &", AddressLine1 als Postal, AddressLine2 als PostalSuburb, AddressLine3 als StreetAddress, Stadt als Vorort, Bundesland, PLZ als PostalCode, AddressType " Ende If

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

Dim qryDef Als 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

Visual Basic sagt, dass der Fehler ist dies Zeile qryDef.s ql = sql.

vielen dank!

+0

Welchen Wert hat Ihre SQL-Variable kurz vor der Zeile qryDef.sql = sql? Ich denke, dass dieser Wert Ihnen viel über das Problem erzählen wird. Sie können den Wert ermitteln, indem Sie den Code debuggen und die Variable untersuchen. Willkommen bei Stackoverflow - bearbeite deine Frage, um die Formatierung zu korrigieren, da es momentan fast unmöglich ist, sie zu lesen. – user2316154

+0

Vielen Dank für Ihre Antwort, dies ist der Wert Wenn Me.chkExportAddress = True Dann 'sql = sql & ", AdresseLine1, AddressLine2, Stadt, Staat, Postleitzahl, AddressType" sql = sql & ", AddressLine1 wie PostalAddress, AddressLine2 als PostalSuburb, AddressLine3 als StreetAddress, Stadt als Vorort, Bundesland, Postleitzahl als PostalCode, AddressType " End If sql = sql &", Klassifizierung, KlassifizierungKopie, Referenznummer, RechnungKommentare, KontoKommentare, Status, LastKontaktDatum, Notizen " –

+0

der Fehler sagt Syntaxfehler (fehlender Operator) im Abfrageausdruck 'AddressLine1 as PostalAddress' –

Antwort

0

Okay, ich denke, das ist das Problem (es ziemlich schwer ist nur mit diesem kleinen Schnipsel zu sagen, mit zu arbeiten.)

den Apostroph markiert Nach unten einer Zeile:

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 " 

zu

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 " 

Diese kommentiert die falsche Linie und ersetzt sie durch eine gute. Das AS-Schlüsselwort in der GROUP BY-Anweisung verursacht das Problem.

+0

danke !, aber wissen Sie, zeigen Sie mir diesen Fehler.Laufzeit '3122' Sie haben versucht, eine Abfrage auszuführen, die den angegebenen Ausdruck 'StreetAddress' nicht als Teil einer Aggregatfunktion enthält. Visual Basic zeigen Sie mir diese Zeile wie Fehler DoCmd.OutputTo acOutputQuery, "qryContactExport", acFormatXLS, Application.CurrentProject.Path & "\ Temp.xls", True –

+0

Jetzt ist perfekt, vielen Dank, ich füge nur hinzu AddressLine3 in sql = sql & ", AdresseLine1, AddressLine2, Ort, Staat, Postleitzahl, AdressTyp". so vielen dank !!! –

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