D
Drew
Hi All,
I have an append query running from code (see SQL statement at
bottom). The query has two calculated expressions; one is from a
variable. The table field that is being assigned from a variable is
indexed (no duplicates).
The append query fails when the indexed field is a duplicate (good)
but no error message comes up (bad). Ultimately, I want to be able to
trap the duplicate error and present a custom msgbox. Is there any
reason it would not give the error when I run it from VBA (the same
query made in design view gives an error)?
Code:
'Run the Append Query to add the record to the main table and add the
file name and today's date
Set db = CurrentDb()
db.Execute "INSERT INTO survey_main ( Field1, Field2, Field3,
Field4, Field5, ImportDate, TextFile )" & _
" SELECT TempTable.field1, TempTable.field2, TempTable.field3,
TempTable.field4," & _
"TempTable.field5, Int(Now()) AS Expr1, '" & strFile & "' AS Expr2
FROM TempTable;"
Set db = Nothing
Thanks,
Drew
I have an append query running from code (see SQL statement at
bottom). The query has two calculated expressions; one is from a
variable. The table field that is being assigned from a variable is
indexed (no duplicates).
The append query fails when the indexed field is a duplicate (good)
but no error message comes up (bad). Ultimately, I want to be able to
trap the duplicate error and present a custom msgbox. Is there any
reason it would not give the error when I run it from VBA (the same
query made in design view gives an error)?
Code:
'Run the Append Query to add the record to the main table and add the
file name and today's date
Set db = CurrentDb()
db.Execute "INSERT INTO survey_main ( Field1, Field2, Field3,
Field4, Field5, ImportDate, TextFile )" & _
" SELECT TempTable.field1, TempTable.field2, TempTable.field3,
TempTable.field4," & _
"TempTable.field5, Int(Now()) AS Expr1, '" & strFile & "' AS Expr2
FROM TempTable;"
Set db = Nothing
Thanks,
Drew