我在我的代码中使用这个插入语句在vba excel中,但我无法将其分解为多行
SqlQueryString = "Insert into Employee values(" & txtEmployeeNo.Value & " _
,'" & txtContractStartDate.Value & "' _
,'" & txtSeatNo.Value & "' _
,'" & txtFloor.Value & "','" & txtLeaves.Value & "')"
Run Code Online (Sandbox Code Playgroud)
它给出了错误"预期的声明结束".Plz的帮助.
Dou*_*ugM 44
您不能在字符串中使用VB行继续符.
SqlQueryString = "Insert into Employee values(" & txtEmployeeNo.Value & _
"','" & txtContractStartDate.Value & _
"','" & txtSeatNo.Value & _
"','" & txtFloor.Value & "','" & txtLeaves.Value & "')"
Run Code Online (Sandbox Code Playgroud)
Geo*_*set 11
您可以简单地在多个步骤中创建字符串,这有点多余,但它可以使代码保持可读性并在调试或编辑时保持健全
SqlQueryString = "Insert into Employee values("
SqlQueryString = SqlQueryString & txtEmployeeNo.Value & " ,"
SqlQueryString = SqlQueryString & " '" & txtEmployeeNo.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtContractStartDate.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtSeatNo.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtContractStartDate.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtSeatNo.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtFloor.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtLeaves.Value & "' )"
Run Code Online (Sandbox Code Playgroud)
如果长串到多行会让您感到困惑.然后你可以安装mz-tools addin这是一个免费软件,并有实用程序为你分割线.
如果你的字符串如下所示
SqlQueryString = "Insert into Employee values(" & txtEmployeeNo.Value & "','" & txtContractStartDate.Value & "','" & txtSeatNo.Value & "','" & txtFloor.Value & "','" & txtLeaves.Value & "')"
Run Code Online (Sandbox Code Playgroud)
只需选择字符串>右键单击VBA IDE>选择MZ工具>拆分线
