8

我对 VBA 环境完全陌生。我试图将这条线分成多条线,但我失败了。有人可以帮我把这段代码分成多行吗?

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 & "';"

更新:我用 &_ 试过这个,但我得到一个语法错误,代码在 VBA 中变成红色。我用逗号或引号弄错了吗?我不知道。

                        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 & "';"

更新 2:

有用!有用!有用!感谢@Bathsheba,@TheLaurens :)

4

1 回答 1

13

在 VBA 中,一个空格后跟下划线,之后没有其他任何东西给你一个换行符。

例如

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

但不要在字符串文字中换行:这是语法错误。

您可以拥有的换行符数量有一个非常小的限制。

于 2013-10-17T08:55:31.917 回答