When I run the following query:
INSERT INTO outRawTbl
SELECT *
FROM (select * from [out|noRFI_BS_noRT]
union all
select * from [out|noRFI_BS_RT]) AS [%$##@_Alias];
I get this error:
Microsoft Access set 3854 field(s) to Null due to a type conversion failure
When I run the query as:
INSERT INTO outRawTbl
SELECT *
FROM (select * from [out|noRFI_BS_noRT]
union
select * from [out|noRFI_BS_RT]) AS [%$##@_Alias];
then I don't get this type conversion error, and all the data inserts successfully. I need to use UNION ALL
because some of the fields in the queries are Memo fields and they'll be truncated to 255 chars if I use UNION
.
I guess I can start trying to insert fields one at a time from the queries, but there are around 50 fields in each query and that will take a lot of time. Is there a quick way to find out which field is causing the problem with UNION ALL
?
EDIT:
Solved and uncovered another problem. I took Gordon's idea of running the queries as separate INSERT
operations instead of using UNION ALL
. I then iterated through each field in the query, doing a separate insert to find the field that was causing the conversion error, using this code:
Sub findProblemField()
Dim qdf As QueryDef
Dim sql As String
Dim fld As Field
For Each qdf In CurrentDb.QueryDefs
If InStr(qdf.Name, "out|") Then
For Each fld In qdf.Fields
sql = "insert into outrawtbl select top 1 " & _
"[" & qdf.Name & "].[" & fld.Name & "] from [" & qdf.Name & "]"
CurrentDb.Execute sql, dbFailOnError
Next
End If
Next
End Sub
This led me to discover that one of the fields that is a string in the SELECT
query is a Date/Time in the destination field, and a blank string value is what's throwing the error. Working on resolving this now...