D
dgy
I am having problems with SQL append queries (INSERT INTO etc) in Access 2007
whenever a target table has a field with a validation rule that uses Like.
Whenever I run the SQL INSERT command, it refuses to append any records and
gives the reason as the validation text of a field in the target table that
contains a Like clause in its validation rule. If I remove the Like part of
the validation rule in the target table, it runs okay. But the records that
should be inserted are valid under the unadjusted rule (ie pass the like
test).
That is confirmed because if I replace the SQL command (called through
CurrentProject.Connection.Execute) with an Access append query that has
exactly the same underlying SQL syntax (called through DoCmd.OpenQuery) then
the records are appended no problem. I have used this as a temporary work
around and test.
However I really don't want to have pre-constructed Access queries lying
around for this purpose. It arises a lot in the system I am working on and
there is sufficient variability that it would be much easier to be able to
construct SQL to suit the circumstance of the particular insert/append.
The issue seems to be something to do with like validation clauses and
perhaps a SQL/Access difference but as far as I can gather from the reference
docs there shouldn't be a problem. The Like clauses tested so far are about
ensuring particular forms of text usually to do with making sure particular
characters are digits eg Like "C####" (so "C1234" is valid); Like "#######"
(so "1234567" is valid). The source data complies with the requirements
although it gets rejected .
I don't know whether it makes any difference but in each case the source
table is in the current database while the target is a linked table in
another. All are Access 2007 databases.
TIA,
dgy
whenever a target table has a field with a validation rule that uses Like.
Whenever I run the SQL INSERT command, it refuses to append any records and
gives the reason as the validation text of a field in the target table that
contains a Like clause in its validation rule. If I remove the Like part of
the validation rule in the target table, it runs okay. But the records that
should be inserted are valid under the unadjusted rule (ie pass the like
test).
That is confirmed because if I replace the SQL command (called through
CurrentProject.Connection.Execute) with an Access append query that has
exactly the same underlying SQL syntax (called through DoCmd.OpenQuery) then
the records are appended no problem. I have used this as a temporary work
around and test.
However I really don't want to have pre-constructed Access queries lying
around for this purpose. It arises a lot in the system I am working on and
there is sufficient variability that it would be much easier to be able to
construct SQL to suit the circumstance of the particular insert/append.
The issue seems to be something to do with like validation clauses and
perhaps a SQL/Access difference but as far as I can gather from the reference
docs there shouldn't be a problem. The Like clauses tested so far are about
ensuring particular forms of text usually to do with making sure particular
characters are digits eg Like "C####" (so "C1234" is valid); Like "#######"
(so "1234567" is valid). The source data complies with the requirements
although it gets rejected .
I don't know whether it makes any difference but in each case the source
table is in the current database while the target is a linked table in
another. All are Access 2007 databases.
TIA,
dgy