0

我试图调用一个名为 Ins_to_temp 的 VBA 过程,但它不起作用。奇怪,因为 Ins_to_temp 是从另一个过程的模型构建的:Truncate_table 确实有效!

您能帮我理解为什么这会在“Ins_to_temp(x,y,z)”行出现错误 - 它说缺少“=”!(好像它是一个函数,但它显然是一个过程)

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

作为参考,这里是一个有效的过程:

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

我可以称之为:Truncate_table("coll") 谢谢

4

2 回答 2

1

你的问题是一个错字:

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
于 2013-03-12T07:58:34.323 回答
1

那么这个呢,它有效吗?

Sub Test()
   Ins_to_temp tbl1:="temp_clients", tbl2:="clients", idx:="202"
End Sub
于 2013-03-12T08:16:13.407 回答