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

syntax error in execute statement

Status
Not open for further replies.

vaughn9

Technical User
Sep 23, 2001
183
I am using an adodc control and a datagrid to store text box data from visual basic. The word Month is being used as one of the field names in my databae but every time I try to run the code viusal basic gives me a syntax error statement. If I change Month to another word it runs perfectly. I am trying to figure out why I can't use the word month. here is the code line that is giving me the syntax error. It does not seem to like the word Month.

mycon.Execute "INSERT INTO budgettable(Month, Expense, Amount) VALUES ('" & Form1.Text1.Text & "','" & Form1.Text2.Text & "','" & Form1.Text3.Text & "')"

if I change month to strmonth it works but I don't want my database field to be named strmonth I want to use the word month

Any suggestions
 
The word Month is a reserved word in VB. If you really must use it as a field name then refer to it in square brackets:
[tt]
mycon.Execute "INSERT INTO budgettable([Month], Expense, Amount)[/tt]

Due to the likelihood of confusion and error, it is normally recommended that you shouldn't use reserved words for variables or field names.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
I guess I'm not getting it -- in the code from vaughn9, the "month" is part of the SQL statement (column name in the budgettable table). How could the fact that month is a reserved word in VB affect a literal in a SQL statement?

I could see this if "month" were a reserved word in MS-Access or SQL Server. But as it's shown, that value gets sent to ADO, and is not interpreted by VB.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks for the correction chiph, my bad. Month is a reserved word in VB, in Access and in SQL.

I would still advise against the use of reserved words as Field names

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top