Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't use string for a table name within runsql delete statement 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I am trying to use an runsql statement to run a delete query using a string for the table. I have tried many different ways to do this with no luck. I usually get compile errors the current method I am using the error message is Cant find the table strTbl1Namewoext you are looking for. Any help is greatly apprecaited.

Code:
Dim strDelete As String
Dim strTbl1Namewoext As String

strTbl1Namewoext = "NBM_CS_Data"

strDelete = "DELETE * FROM [strTbl1Namewoext]"
DoCmd.RunSQL strDelete
 
strDelete = "DELETE * FROM " & strTbl1Namewoext

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
And, in case you have strange table names:
strDelete = "DELETE * FROM [" & strTbl1Namewoext & "]"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Once again, you can help yourself by:

Code:
strDelete = "DELETE * FROM [strTbl1Namewoext]"[red]
Debug.Print strDelete[/red]
DoCmd.RunSQL strDelete

so you could see what's wrong

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top