2016-03-31 18 views
0

lütfen, yardıma ihtiyacım olduğunda, bu hata oluştu, yardıma ihtiyacım var.Microsoft Access Çalışma zamanı hatası '3075' sorgu ifadesinde

sql = sql & "Grup tarafından kişi kimliği, TitleID, KişiAdı, SuffixID, Şirket, JobTitle, posta1, Email2, Email3, WebPageAddress, IMAddress" Eğer Gerçek Me.chkExportPhone = Sonra sql = sql & ", PhoneNumber, PhoneNumberType " sonu ise Eğer Me.chkExportAddress = true Then 'sql = sql & " AddressLine1, AddressLine2, Şehir, Eyalet, Zip, AddressType" sql = sql &", AddressLine1 PostalSuburb gibi AddressLine3 olarak PostalAddress, AddressLine2 olarak StreetAddress, Banliyö gibi Şehir, Eyalet, Posta Kodu olarak Zip, AddressType " End If

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

Dim qryDef QueryDef Seti qryDef = CurrentDb.QueryDefs ("qryContactExport") qryDef.sql = sql Seti qryDef = Hiçbir şey 'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9 gibi, "qryContactExport", " C: \ Temp \ Temp.xls" DoCmd.OutputTo acOutputQuery, "qryContactExport", acFormatXLSOutputFormat, Application.CurrentProject.Path & "\ Temp.xls" true End Sub

Görsel temel hatası bu olduğunu söylüyor satır qryDef.s ql = sql.

çok teşekkürler!

+0

sql değişkeninizde qryDef.sql = sql satırından hemen önceki değer nedir? Bence bu değer sorunun ne olduğu hakkında çok şey söyleyecektir. Kodu ayıklayarak ve değişkeni inceleyerek değeri alabilirsiniz. Ayrıca, Stackoverflow'a hoş geldiniz - şu anda okumak neredeyse imkansız olduğu için biçimlendirmeyi düzeltmek için sorunuzu düzenleyin. Cevabınız için – user2316154

+0

sayesinde, bu değer ise Me.chkExportAddress = Doğru Sonra = sql & "AddressLine1, AddressLine2, Şehir, Eyalet, Zip, AddressType" sql = sql & "PostalAddress, AddressLine2 olarak, AddressLine1 'sql , Sınıflandırma, ClassificationCopy, ReferenceNumber, InvoiceComments, AccountComments, Durum, LastContactDate, Notlar " –

+0

hata diyor " sql = sql & Eğer sonu" PostalSuburb, StreetAddress olarak AddressLine3, Banliyö, Devlet, PostaKodu olarak Zip olarak City, AddressType olarak Sözdizimi hatası (eksik operatör) sorgu ifadesinde 'AddressLine1 PostalAddress' olarak –

cevap

0

Tamam, (Bu çalışmayı sadece bu küçük snippet'iyle söylemek zor türüdür.) Bu sorun olduğunu düşünüyorum

aşağı bir satır işaretli tek alıntı taşıyın:

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 " 

Bu yanlış çizgiyi dışında yorumlar ve iyi bir biri ile değiştirir. GROUP BY deyimindeki AS anahtar sözcüğü soruna neden oluyor.

+0

Teşekkürler! Ama biliyorum bana bu hatayı göster.Çalışma zamanı '3122' , bir toplama işlevinin parçası olarak belirtilen 'StreetAddress' ifadesini içermeyen bir sorguyu çalıştırmayı denediniz. visual basic gösteri bana hata DoCmd.OutputTo acOutputQuery, "qryContactExport", acFormatXLSOutputFormat, Application.CurrentProject.Path & "\ Temp.xls" gibi bu hat Gerçek –

+0

Şimdi mükemmel, çok teşekkür ederim, ben sadece eklemek AddressLine3, sql = sql & ", AddressLine1, AddressLine2, City, State, Zip, AddressType". çok teşekkür ederim! –

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 
İlgili konular