docmd.runsql(“delete * from& strValue&”)

时间:2015-12-10 00:54:53

标签: sql ms-access access-vba

以下代码读取组合框中所选查询的名称。然后,它找到与该查询对应的表,并且必须从中删除数据,以便将Insert插入到select查询中。我有Select into查询,但每次都会删除表。你能帮忙解决docmd.Runsql(“delete * from .....”)行中的语法吗?我需要在用数据重新填充它之前清空表,因此想在表中传递一个带有表名的字符串值sql命令。谢谢你的帮助!

For Each valSelect In Me.Combo29.ItemsSelected
  DoCmd.SetWarnings (WarningsOff)
  strValue = Me.Combo29.ItemData(valSelect)
    strValue3 = DLookup("TableName", "[List of Queries]", "QueryName = '" & strValue & "'")
    DoCmd.RunSQL ("delete * from '& strValue3 &'")
    DoCmd.OpenQuery (strValue)
    Me.Combo29.Selected(valSelect) = False

1 个答案:

答案 0 :(得分:0)

只需从DELETE语句中删除星号即可。此外,你的双引号看起来不正确。如果你的表名中有空格,可能还想添加一些方括号:

DoCmd.RunSQL "delete from [" & strValue3 & "]"