Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default INSERT INTO sql statement causing error

I have the following SQL statement:

statement = "INSERT INTO Table1 (Field1, Field2, Field3)" & _
" VALUES ('" & ComboBox1 & "', " & ListBox1 & ", '" & ListBox2 & "')"

I have a compound key in that the combination of Field1, Field2, and
Field3 must be a unique combination in the table. When the combination
is unique, everything is fine, when the combination is not unique, the
code throws an error, which it should. I'm having trouble handling the
error and am looking for some help.

The specific error is:

Run time error '-2147467259 (80004005)':
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key or
relationship. Change the data in the field or fields that contain
duplicate data, remove the index, or redefine the index to permit
duplicate entries and try again.

Again, the error is properly generating, I'm just having trouble
handling it. I think there must be some way to handle it using On
Error Goto, but I can't figure it out.

Any help is appreciated.

Thanks,
Mike.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default INSERT INTO sql statement causing error

Show the code which runs the SQL - easier to change existing code than to
write a whole "example" sub...

Tim

--
Tim Williams
Palo Alto, CA


"Michael Malinsky" wrote in message
oups.com...
I have the following SQL statement:

statement = "INSERT INTO Table1 (Field1, Field2, Field3)" & _
" VALUES ('" & ComboBox1 & "', " & ListBox1 & ", '" & ListBox2 & "')"

I have a compound key in that the combination of Field1, Field2, and
Field3 must be a unique combination in the table. When the combination
is unique, everything is fine, when the combination is not unique, the
code throws an error, which it should. I'm having trouble handling the
error and am looking for some help.

The specific error is:

Run time error '-2147467259 (80004005)':
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key or
relationship. Change the data in the field or fields that contain
duplicate data, remove the index, or redefine the index to permit
duplicate entries and try again.

Again, the error is properly generating, I'm just having trouble
handling it. I think there must be some way to handle it using On
Error Goto, but I can't figure it out.

Any help is appreciated.

Thanks,
Mike.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's causing error message? Jim Tibbetts Excel Worksheet Functions 4 November 12th 08 06:13 PM
Query causing #ref error in spreadsheet endro Excel Discussion (Misc queries) 0 May 14th 08 12:03 AM
VLOOKUP Formula causing an error japc90 Excel Discussion (Misc queries) 2 July 25th 06 11:36 PM
strange error message following INSERT INTO statement Loane Sharp Excel Programming 5 August 27th 04 08:27 AM
Message box causing error in code Calligra Excel Programming 0 July 7th 04 02:46 PM


All times are GMT +1. The time now is 10:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"