0

How do I format this line of code correctly to allow me to have the parenthesis inside the statement string?

db.Execute("SQL DB", "INSERT INTO ABPCahirMIS.dbo.TESTDB (TEST) VALUES(1) ")

javawocky
  • 899
  • 2
  • 9
  • 31
  • what do you mean exactly? could you give an example statement of what the statement would be like? – Jeremy C. May 22 '15 at 13:55
  • @Jeremy C. When I run it it tells me I cannot use a parenthesis when calling a sub? – javawocky May 22 '15 at 13:58
  • 1
    try putting call before your statement like so: Call db.Execute("SQL DB", "INSERT INTO ABPCahirMIS.dbo.TESTDB (TEST) VALUES(1) ") – Jeremy C. May 22 '15 at 13:59
  • you might want to read this if that one doesn't work: http://stackoverflow.com/questions/14902134/cannot-use-parentheses-when-calling-a-sub-error-800a0414-vbs – Jeremy C. May 22 '15 at 14:04
  • 2
    If the result of the call is not being assigned to a variable, VBA doesn't want the outer parenthesis around the Execute call. – David W May 22 '15 at 14:04

2 Answers2

2

In VBA, if you call a sub, you don't add parentheses to the call, eg:

db.Execute "SQL DB", "INSERT INTO ABPCahirMIS.dbo.TESTDB (TEST) VALUES(1)"
David W
  • 10,062
  • 34
  • 60
0

Something like this:

Dim dbs As DAO.Database, sql as String
Set dbs = "SQL DB"
sql = INSERT INTO ABPCahirMIS.dbo.TESTDB (TEST) VALUES(1)
dbs.Execute sql, dbFailOnError
SQLHound
  • 546
  • 11
  • 24