2013-10-17 4 views
7

Ich bin völlig neu in einer VBA-Atmosphäre. Ich habe versucht, diese Linie in mehrere Zeilen zu unterteilen, aber ich habe versagt. Kann mir jemand helfen, diesen Code in mehrere Zeilen zu zerlegen?brechen eine lange sql vba Aussage in mehrere Zeilen

DoCmd.RunSQL "UPDATE INDIVIDUAL SET INDIVIDUAL.INDI_FIRSTNAME = '" & prospect_contact!FirstName & "', INDIVIDUAL.INDI_LASTNAME = '" & prospect_contact!LastName & "', INDIVIDUAL.INDI_TEL = '" & prospect_contact!BusinessTelephone & "', INDIVIDUAL.INDI_ADDRESS1 = '" & Replace(prospect_contact!Street, "'", "") & "', INDIVIDUAL.INDI_ADDRESS2 = '" & Replace(prospect_contact!Street1, "'", "") & "', INDI_STATUS = '" & pro & "',INDIVIDUAL.INDI_FUNEL1 = '" & prospect_contact!QualificationStatus & "', INDIVIDUAL.INDI_COUNTRY = '" & prospect_contact!Country_Employer & "', INDIVIDUAL.ACCT_NAME = '" & Replace(prospect_contact!Employer, "'", "") & "' WHERE INDIVIDUAL.INDI_FULLNAME = '" & key & "';" 

UPDATE: Ich habe versucht, dies mit dem & _ aber ich bekomme einen Syntaxfehler und der Code wird in VBA rot. Mache ich einen Fehler mit den Kommas oder den Anführungszeichen. Ich habe keine Ahnung.

     DoCmd.RunSQL "UPDATE INDIVIDUAL SET INDIVIDUAL.INDI_FIRSTNAME = '" & prospect_contact!FirstName & "', & _ 
        INDIVIDUAL.INDI_LASTNAME = '" & prospect_contact!LastName & "', & _ 
        INDIVIDUAL.INDI_TEL = '" & prospect_contact!BusinessTelephone & "', & _ 
        INDIVIDUAL.INDI_ADDRESS1 = '" & Replace(prospect_contact!Street, "'", "") & "', & _ 
        INDIVIDUAL.INDI_FUNEL1 = '" & prospect_contact!QualificationStatus & "', & _ 
        INDI_STATUS = '" & pro & "', & _ 
        INDIVIDUAL.INDI_COUNTRY = '" & prospect_contact!Country_Employer & "', & _ 
        INDIVIDUAL.ACCT_NAME = '" & Replace(prospect_contact!Employer, "'", "") & "' & _ 
        WHERE INDIVIDUAL.INDI_FULLNAME = '" & key & "';" 

UPDATE 2:

ES FUNKTIONIERT! ES KLAPPT! ES KLAPPT! Danke an @Bathsheba, @TheLaurens :)

Antwort

11

In VBA ein Leerzeichen gefolgt von Unterstrich und nichts sonst gibt Ihnen einen Zeilenumbruch.

z.B.

DoCmd.RunSQL "UPDATE INDIVIDUAL SET INDIVIDUAL.INDI_FIRSTNAME = '" & _ 
prospect_contact!FirstName & "', INDIVIDUAL.INDI_LASTNAME = '" & _ 
etc 

Aber nicht Zeilen in einem String-Literal zu brechen: das ist ein Syntaxfehler.

Die Anzahl der möglichen Zeilenumbrüche ist überraschend gering.

+0

hatte nie Probleme damit, und ich habe einige große SQL verwendet! ;) & _ sollte gut funktionieren, stellen Sie sicher, dass Sie dort Platz haben. Außerdem bevorzuge ich es, logische Stellen zu durchbrechen, dh nicht nach =, sondern eine Auswahl, von, wo, usw. Zeile. – TheLaurens

+1

@TheLaurens; Ich denke, die Grenze ist in den zwanziger Jahren. (Ich treffe einmal einen VBA Code Generator). – Bathsheba

+0

Ich versuchte mit & _ aber es funktioniert nicht. Ich habe den Post aktualisiert – codious

Verwandte Themen