G
Guest
Basically what I am trying to do is use VBA to generate an SQL statement/query based on a table called (LossTable) and then take the result of this select statement and place it into a temporary table (tempdata). The temporary table already exists and contains the same data structure as the (LossTable) table, just no data
I know that the Select part of my SQL worked prior to adding the INSERT INTO portion. It seems that the whole SQL segment, including the INSERT INTO, compiles, but when it gets to the execute step it blows up. I get "syntax error in INSERT INTO statement" error 3134.
Can anyone help me figure out how to fix this problem? Also, once I get that problem fixed, is there an easy way to use VBA to delete all of the data in a table without deleting the structure and field settings?
thanks in advance for any help
ti
This is all of the pertinent code to my question. The arrays and other variables are defined and are assigned values, but since that's not part of the problem, it's not included
Dim db As Databas
Set db = CurrentD
strSQL = "INSERT into tempdata (Plant,Area,SubArea,AreaID,Date,Breakdown,Changeover,Tool,Startup,"
& "MinorStoppage,Speed,Defect,Rework,ScheduledDownTime,"
& "Management,Motion,LineBalance,MonitoringAdjust,Scrap,"
& "DieJigFixture,Energy)"
& " SELECT Plant,Area,SubArea,AreaID,Date,Breakdown,Changeover,Tool,Startup,"
& "MinorStoppage,Speed,Defect,Rework,ScheduledDownTime,"
& "Management,Motion,LineBalance,MonitoringAdjust,Scrap,"
& "DieJigFixture,Energy"
& "FROM LossTable "
& "WHERE AREA IN ('" & areaarray(1) & "',"
& " '" & areaarray(2) & "',"
& " '" & areaarray(3) & "',"
& " '" & areaarray(4) & "',"
& " '" & areaarray(5) & "',"
& " '" & areaarray(6) & "')"
& "AND PLANT IN ('" & plantarray(1) & "','" & plantarray(2) & "')"
& "AND DATE = " & msg & "
db.Execute strSQL, dbFailOnError
I know that the Select part of my SQL worked prior to adding the INSERT INTO portion. It seems that the whole SQL segment, including the INSERT INTO, compiles, but when it gets to the execute step it blows up. I get "syntax error in INSERT INTO statement" error 3134.
Can anyone help me figure out how to fix this problem? Also, once I get that problem fixed, is there an easy way to use VBA to delete all of the data in a table without deleting the structure and field settings?
thanks in advance for any help
ti
This is all of the pertinent code to my question. The arrays and other variables are defined and are assigned values, but since that's not part of the problem, it's not included
Dim db As Databas
Set db = CurrentD
strSQL = "INSERT into tempdata (Plant,Area,SubArea,AreaID,Date,Breakdown,Changeover,Tool,Startup,"
& "MinorStoppage,Speed,Defect,Rework,ScheduledDownTime,"
& "Management,Motion,LineBalance,MonitoringAdjust,Scrap,"
& "DieJigFixture,Energy)"
& " SELECT Plant,Area,SubArea,AreaID,Date,Breakdown,Changeover,Tool,Startup,"
& "MinorStoppage,Speed,Defect,Rework,ScheduledDownTime,"
& "Management,Motion,LineBalance,MonitoringAdjust,Scrap,"
& "DieJigFixture,Energy"
& "FROM LossTable "
& "WHERE AREA IN ('" & areaarray(1) & "',"
& " '" & areaarray(2) & "',"
& " '" & areaarray(3) & "',"
& " '" & areaarray(4) & "',"
& " '" & areaarray(5) & "',"
& " '" & areaarray(6) & "')"
& "AND PLANT IN ('" & plantarray(1) & "','" & plantarray(2) & "')"
& "AND DATE = " & msg & "
db.Execute strSQL, dbFailOnError