PDA

View Full Version : Sql Insert Syntax Error



technocraze
12-18-2006, 08:49 AM
Hi guys,

I have encountered an error while inserting the records to MS Acess using Visual basic. I tried to insert the records to the database by executing an sql query with a where clause. This 'where' condition is needed because i need to match the corresponding records from my drop-down combo box. However, when it its executed there is a syntax error indicating missing semi-colon

My sql query goes:
insert into [TableName] (field1, field2, field3) values (textBox1, textBox2, textbox3) where field4 = combo1;

Error: missing semi-colon

Any assistance or code reference is very much appreciated
Thanks in advance!

Norie
12-18-2006, 12:29 PM
Could you post the actual code?

Tommy
12-18-2006, 01:12 PM
Hi technocraze :hi:

You need an update query. Something Like

SQL = "update " & TableName & " set field1 = " & TextBox1.Text & ", field2 = " & TextBox2.Text & ", field3 = " & TextBox3.Text & " where field4 = " & combo1.Text & ";"

cbeltrante
12-21-2006, 05:54 AM
Could you post the actual code?

I agree, this would be a big help if you could post the actual code that you are using.

XLGibbs
12-26-2006, 09:28 PM
The update statement above seems the way to go.

You can't insert records with a conditional applied to those same records, it has to be an update statement.

If you need to insert records where the Combo selection becomes the 4th field, then make Combo1.Text your 4th value and add Field4 to your insert statement.

Insert = NEW records only

Update = MODIFY existing records.