gpt4 book ai didi

vba - 将一个长的 sql vba 语句分成多行

转载 作者:行者123 更新时间:2023-12-04 06:19:44 27 4
gpt4 key购买 nike

我对 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 :)

最佳答案

在 VBA 中,一个空格后跟下划线和 没什么否则之后会给你一个换行符。

例如

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

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

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

关于vba - 将一个长的 sql vba 语句分成多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19422064/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com