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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL error

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
I'm using the following line to add a field to a table (.mdb):

conmdb.Execute ("ALTER TABLE tblReportData ADD COLUMN " & FieldName & " String")

I use this many times in a loop but on certain times it falls over. Namely when FieldName="TIME" or FieldNAme="BIT". I can not see ANY reason why this is happening:

Syntax error in field definition

Am I using illegal words that Access reserves for someting else? I dont seem to find any evidence of this though. I can call a field "TIME" in the access tabel design window!

I've entered the error code -2147217900

Any tips?

elziko
 
The problem is caused by Jet's built-in expression evaluator, which will indeed treat TIME (and various other words) as a keyword.

It is easily solved by delimiting the intended column name with square brackets so that Jet KNOWS it is a column name:

conmdb.Execute ("ALTER TABLE tblReportData ADD COLUMN [" & FieldName & "] String")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top