access warning message (key violation) crashing program

spaghettijim

New member
Joined
Feb 2, 2005
Messages
2
Programming Experience
Beginner
I'm sending an insert sql statement to my Access database through vb.net. I've run the sql inside of access so I know it works but it gives me messages that I need to suppress so my program will run without crashing. The table I'm inserting into is indexed and does not allow duplicates. I've turned off the warning messages manually in my access database so this eliminates the message telling you how many records your adding. Though another message wants to pop up telling me about the duplicates I'm trying to add (key violations). How can I suppress this message so when I run my program it doesn't crash.
thanks for your help,
Jim
 
Do I need to catch the error? I was hoping there would be a way to suppress the error.
Here is the sniplet of code:


strSql4 = "INSERT INTO PVL_label ( SITYPE, SFRES, IREF02, CREF01 ) " _

& "SELECT [" & month & "].SITYPE, [" & month & "].SFRES, [" & month & "].IREF02, [" & month & "].CREF01 " _

& "FROM [" & month & "] " _

& "GROUP BY [" & month & "].SITYPE, [" & month & "].SFRES, [" & month & "].IREF02, [" & month & "].CREF01 " _

& "HAVING((([" & month & "].SITYPE) = """ & 1 & """) And (([" & month & "].SFRES) = """ & validinvoice & """)And (([" & month & "].CREF01) = """ & sbu

& """)) " _
& "ORDER BY [" & month & "].IREF02;"

ForecastDB3 =
New System.Data.OleDb.OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & datasource & ";")
ForecastDB3.Open()
selcomm4 =
New System.Data.OleDb.OleDbCommand()
selcomm4.Connection = ForecastDB3
selcomm4.CommandText = strSql4
results = selcomm4.ExecuteNonQuery
 
Back
Top