musgah
asked on
Append/Update queries that violate Required or AllowZeroLength or PrimaryKey rules do not trigger error messages when executed from VBA. Is there a way to correct this?
This presents a major threat. Suppose you archive data from TableXYZ to TableABC and then purge from TableXYZ the records you assume have been transferred. BIG MISTAKE. TableABC will be missing the violating records, and those records will have been deleted from TableXYZ, forever.
For example:
INSERT INTO TableABC ( aPrimaryKeyFieldWithNullsA ndEmptyStr ingsForbid den)
SELECT AFieldContainingNullsOrEmp tyStrings
FROM TableXYZ;
will trigger an error message when run from the QBE screen if TableXYX contains nulls or empty strings, or if it attempts to insert a value that violates TableABC's primary key. However, the following VBA code will let you believe everything is OK when, in fact, not all records from TableXYZ were appended:
Sub test()
Dim sql As String
Dim rs As DAO.Recordset
sql = ""
sql = sql & "INSERT INTO TableABC ( aPrimaryKeyFieldWithNullsA ndEmptyStr ingsForbid den ) "
sql = sql & "SELECT AFieldContainingNullsOrEmp tyStrings "
sql = sql & "FROM TableXYZ"
CurrentDb.Execute sql
End Sub
For example:
INSERT INTO TableABC ( aPrimaryKeyFieldWithNullsA
SELECT AFieldContainingNullsOrEmp
FROM TableXYZ;
will trigger an error message when run from the QBE screen if TableXYX contains nulls or empty strings, or if it attempts to insert a value that violates TableABC's primary key. However, the following VBA code will let you believe everything is OK when, in fact, not all records from TableXYZ were appended:
Sub test()
Dim sql As String
Dim rs As DAO.Recordset
sql = ""
sql = sql & "INSERT INTO TableABC ( aPrimaryKeyFieldWithNullsA
sql = sql & "SELECT AFieldContainingNullsOrEmp
sql = sql & "FROM TableXYZ"
CurrentDb.Execute sql
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER