0
votes

The below code reads through the names of selected queries in the combo box. Then it finds the table that corresponds to that query and has to delete data from it, in order to run Insert into select query. I had Select into query, but this would delete the tables each time. Can you please help with the syntax in the docmd.Runsql ("delete * from .....) line? I need to empty the table before repopulating it with data and was therefore thinking of passing a string value with table name in the sql command. Thank you for help!

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

1 Answers

0
votes

Just remove the asterisk from your DELETE statement. Also, your double quotes don't look right. Might want to add some square brackets as well in case your table names have spaces in them:

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