简体   繁体   English

调用VBA过程 - 错误丢失=

[英]Calling VBA procedure - error missing =

I tried to call a VBA procedure named Ins_to_temp but it doesn't work. 我试图调用一个名为Ins_to_temp的VBA程序,但它不起作用。 Strange, as Ins_to_temp is built from the model of another procedure: Truncate_table that DOES work! 奇怪,因为Ins_to_temp是从另一个程序的模型构建的:Truncate_table可以工作!

Can you please help me understand why this gives an error on line "Ins_to_temp(x,y,z)" - it says an "=" is missing! 能否帮助我理解为什么这会在“Ins_to_temp(x,y,z)”行上出现错误 - 它表示缺少“=”! (as if it was a function but it's obviously a procedure) (好像它是一个功能,但它显然是一个程序)

Sub Ins_to_temp(tbl1 As String, tbl2 As String, idx As String)
    Connect
    Dim strQ As String
    Set rstR = New ADODB.Recordset
    rstR.CursorType = adOpenStatic
    strQ = "insert into " & tbl1 & " (select * from " & tbl2 & " where id = '" & idx & "')"
    rstRec.Open strQ, objCon, adOpenDynamic, adLockOptimistic
End Sub

Sub Test()
   Ins_to_temp("temp_clients","clients","202")

End Sub

For the reference, here is a procedure that DOES work: 作为参考,这是一个工作的程序:

Sub Truncate_table(tbl1 As String)
    Connect
    Dim strQ As String
    Set rstR = New ADODB.Recordset
    rstR.CursorType = adOpenStatic
    strQ = "DELETE FROM " & tbl1
    rstR.Open strQ, objCon, adOpenDynamic, adLockOptimistic
End Sub

I can call it as: Truncate_table("coll") Thank you 我可以称之为:Truncate_table(“coll”)谢谢

Your problem is a typo : 你的问题是错字:

Sub Ins_to_temp(tbl1 As String, tbl2 As String, idx As String)
    Connect
    Dim strQ As String
    Set rstR = New ADODB.Recordset
    rstR.CursorType = adOpenStatic

    strQry = "insert into " & tbl1 & " (select * from " & tbl2 & " where id = '" & idx & "')"

    ' the line above should be

    strQ = "insert into " & tbl1 & " (select * from " & tbl2 & " where id = '" & idx & "')"

    rstRec.Open strQ, objCon, adOpenDynamic, adLockOptimistic
End Sub

And what about this, does it work? 那怎么样,它有用吗?

Sub Test()
   Ins_to_temp tbl1:="temp_clients", tbl2:="clients", idx:="202"
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM