tags:

views:

32

answers:

1

Syntax question: I am using the code below to call a query in Access VBA

strSQL = "INSERT INTO tblLoanDetails ([ServerName]) VALUES ('Test') WHERE [ID]=3"
Call CurrentDb.Execute(strSQL)

And i am getting a runtime error of "3067: Query must contain atleast one table or query."

the insert statement string looks like this (Threw the var into a text box):

INSERT INTO tblLoanDetails ([ServerName]) VALUES ('Test') WHERE [ID]=3

I also tried adding a semi-colon to the end but with no luck. I also double checked to make sure my table is called tblLoanDetails and my Column names are ServerName, and ID

Appreciate any help.

+1  A: 

Assuming you want to add a new record, you shouldn't have a WHERE clause in this case, since there are no records to examine. Do this:

INSERT INTO tblLoanDetails (ServerName) VALUES ('Test') 

If instead you wish to modify an existing record, do this:

UPDATE tblLoanDetails set ServerName = 'Test' where ID = 3
RedFilter
Are you suggesting I should be updating instead of Inserting?
Josh K
Use INSERT for adding a new record and UPDATE for changing an existing record.
RedFilter
So if i wanted to change the ServerName field from something else, i shouldn't Insert?
Josh K
See my update...
RedFilter