Hi All,
I am trying to combine these two bits of code together so I can basically select the data from one table and transfer this to another table however the table name of the table I am copying to would be based on tblDatabase & the value from the record in the table we're copy from.
It just continues to fail to run and gives a message of Compile Error Syntax.
I am not a coder at all as you can probably guess.
Dim tName As String
Dim strSQL As String
tName = tblDatato & tblDatafrom.COCODE
strSQL = "INSERT INTO " & tName & _
SELECT Acc, Amount, [Desc], JRNAL_LINE FROM
(SELECT Acc, Amount, [Desc], 1 AS JRNAL_LINE
FROM tblDatafrom
WHERE [Ready] = True AND [Acc] IS NOT NULL AND Amount IS NOT NULL
UNION ALL
SELECT Acc1, Amount1, [Desc], 2 AS JRNAL_LINE
FROM tblDatafrom
WHERE [Ready] = True AND [Acc1] IS NOT NULL AND Amount1 IS NOT NULL
UNION ALL
SELECT 271 AS Acc, Amount, [Desc], 3 AS JRNAL_LINE
FROM tblDatafrom
WHERE [Ready] = True AND [Acc] IS NOT NULL AND Amount2 IS NOT NULL)
DoCmd.RunSQL strSQL
Any help would be much appreciated.
Thanks alot
I am trying to combine these two bits of code together so I can basically select the data from one table and transfer this to another table however the table name of the table I am copying to would be based on tblDatabase & the value from the record in the table we're copy from.
It just continues to fail to run and gives a message of Compile Error Syntax.
I am not a coder at all as you can probably guess.
Dim tName As String
Dim strSQL As String
tName = tblDatato & tblDatafrom.COCODE
strSQL = "INSERT INTO " & tName & _
SELECT Acc, Amount, [Desc], JRNAL_LINE FROM
(SELECT Acc, Amount, [Desc], 1 AS JRNAL_LINE
FROM tblDatafrom
WHERE [Ready] = True AND [Acc] IS NOT NULL AND Amount IS NOT NULL
UNION ALL
SELECT Acc1, Amount1, [Desc], 2 AS JRNAL_LINE
FROM tblDatafrom
WHERE [Ready] = True AND [Acc1] IS NOT NULL AND Amount1 IS NOT NULL
UNION ALL
SELECT 271 AS Acc, Amount, [Desc], 3 AS JRNAL_LINE
FROM tblDatafrom
WHERE [Ready] = True AND [Acc] IS NOT NULL AND Amount2 IS NOT NULL)
DoCmd.RunSQL strSQL
Any help would be much appreciated.
Thanks alot