Hi all,
Access 2K
I'm having problems with a piece of code that I wrote to create two tables and append data to those tables once created.
The problem appears to be when the code runs to steps 3 and 4 (see below) step 3 makes a table and inserts data and step 4 appends more data to the newly created table.
Can anyone suggest anything to fix it?
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click
DoCmd.SetWarnings False
'STEP 1: Create Lnk_AreaPicks table from tbl_Areapicks table
DoCmd.RunSQL "SELECT tbl_AreaPicks.PDate, tbl_AreaPicks.ModuleLow, " & _
"tbl_AreaPicks.ModuleHigh, tbl_AreaPicks.ModuleTotal, tbl_AreaPicks.ShelvingT, " & _
"tbl_AreaPicks.RackLow, tbl_AreaPicks.RackHigh, tbl_AreaPicks.Bulk, " & _
"tbl_AreaPicks.OtherT, tbl_AreaPicks.RackTotal, tbl_AreaPicks.TotalHits " & _
"INTO Lnk_AreaPicks " & _
"FROM tbl_AreaPicks " & _
"WHERE (((tbl_AreaPicks.PDate) Between [Forms]![frm_LinkFilter]![FromDate] " & _
"And [Forms]![frm_LinkFilter]![ToDate]))"
'STEP 2: Create Lnk_AreaPicksCrossTab and append Module Low data
DoCmd.RunSQL "SELECT 'Module Low' AS Area, Lnk_AreaPicksTotals.SumOfModuleLow " & _
"AS Total INTO Lnk_AreaPicksCrossTab " & _
"FROM Lnk_AreaPicksTotals"
'STEP 3: Create Lnk_AreaPicksCrossTabTotal table and insert Module totals
DoCmd.RunSQL "SELECT 'Module Total' AS Area, Sum(Lnk_AreaPicks.ModuleTotal)" & _
"AS Total INTO Lnk_AreaPicksCrossTabTotal" & _
"FROM Lnk_AreaPicks " & _
"GROUP BY 'Module Total'"
'STEP 4: Append Module High
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Module High' AS Area, Lnk_AreaPicksTotals.SumOfModuleHigh AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 5: Append Shelving
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Shelving' AS Area, Lnk_AreaPicksTotals.SumOfShelvingT AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 6: Append Rack low
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Rack Low' AS Area, Lnk_AreaPicksTotals.SumOfRackLow AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 7: Append Rack high
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Rack High' AS Area, Lnk_AreaPicksTotals.SumOfRackHigh AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 8: Append Bulk
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Bulk' AS Area, Lnk_AreaPicksTotals.SumOfBulk AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 9: Append Other
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Other' AS Area, Lnk_AreaPicksTotals.SumOfOtherT AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 10: Append Rack Totals
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTabTotal ( Area, Total )" & _
"SELECT 'Rack Total' AS Area, Sum(Lnk_AreaPicks.RackTotal) AS Total" & _
"FROM Lnk_AreaPicks" & _
"GROUP BY 'Rack Total'"
'STEP 11: Append Bulk totals
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTabTotal ( Area, Total )" & _
"SELECT 'Bulk Total' AS Area, Sum(Lnk_AreaPicks.Bulk) AS Total" & _
"FROM Lnk_AreaPicks" & _
"GROUP BY 'Bulk Total'"
'STEP 12: Append Other Totals
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTabTotal ( Area, Total )" & _
"SELECT 'Other Total' AS Area, Sum(Lnk_AreaPicks.OtherT) AS Total" & _
"FROM Lnk_AreaPicks" & _
"GROUP BY 'Other Total'"
DoCmd.SetWarnings True
DoCmd.Close
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
Thanks in advance, Tadynn
Access 2K
I'm having problems with a piece of code that I wrote to create two tables and append data to those tables once created.
The problem appears to be when the code runs to steps 3 and 4 (see below) step 3 makes a table and inserts data and step 4 appends more data to the newly created table.
Can anyone suggest anything to fix it?
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click
DoCmd.SetWarnings False
'STEP 1: Create Lnk_AreaPicks table from tbl_Areapicks table
DoCmd.RunSQL "SELECT tbl_AreaPicks.PDate, tbl_AreaPicks.ModuleLow, " & _
"tbl_AreaPicks.ModuleHigh, tbl_AreaPicks.ModuleTotal, tbl_AreaPicks.ShelvingT, " & _
"tbl_AreaPicks.RackLow, tbl_AreaPicks.RackHigh, tbl_AreaPicks.Bulk, " & _
"tbl_AreaPicks.OtherT, tbl_AreaPicks.RackTotal, tbl_AreaPicks.TotalHits " & _
"INTO Lnk_AreaPicks " & _
"FROM tbl_AreaPicks " & _
"WHERE (((tbl_AreaPicks.PDate) Between [Forms]![frm_LinkFilter]![FromDate] " & _
"And [Forms]![frm_LinkFilter]![ToDate]))"
'STEP 2: Create Lnk_AreaPicksCrossTab and append Module Low data
DoCmd.RunSQL "SELECT 'Module Low' AS Area, Lnk_AreaPicksTotals.SumOfModuleLow " & _
"AS Total INTO Lnk_AreaPicksCrossTab " & _
"FROM Lnk_AreaPicksTotals"
'STEP 3: Create Lnk_AreaPicksCrossTabTotal table and insert Module totals
DoCmd.RunSQL "SELECT 'Module Total' AS Area, Sum(Lnk_AreaPicks.ModuleTotal)" & _
"AS Total INTO Lnk_AreaPicksCrossTabTotal" & _
"FROM Lnk_AreaPicks " & _
"GROUP BY 'Module Total'"
'STEP 4: Append Module High
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Module High' AS Area, Lnk_AreaPicksTotals.SumOfModuleHigh AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 5: Append Shelving
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Shelving' AS Area, Lnk_AreaPicksTotals.SumOfShelvingT AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 6: Append Rack low
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Rack Low' AS Area, Lnk_AreaPicksTotals.SumOfRackLow AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 7: Append Rack high
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Rack High' AS Area, Lnk_AreaPicksTotals.SumOfRackHigh AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 8: Append Bulk
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Bulk' AS Area, Lnk_AreaPicksTotals.SumOfBulk AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 9: Append Other
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTab ( Area, Total )" & _
"SELECT 'Other' AS Area, Lnk_AreaPicksTotals.SumOfOtherT AS Total" & _
"FROM Lnk_AreaPicksTotals"
'STEP 10: Append Rack Totals
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTabTotal ( Area, Total )" & _
"SELECT 'Rack Total' AS Area, Sum(Lnk_AreaPicks.RackTotal) AS Total" & _
"FROM Lnk_AreaPicks" & _
"GROUP BY 'Rack Total'"
'STEP 11: Append Bulk totals
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTabTotal ( Area, Total )" & _
"SELECT 'Bulk Total' AS Area, Sum(Lnk_AreaPicks.Bulk) AS Total" & _
"FROM Lnk_AreaPicks" & _
"GROUP BY 'Bulk Total'"
'STEP 12: Append Other Totals
DoCmd.RunSQL "INSERT INTO Lnk_AreaPicksCrossTabTotal ( Area, Total )" & _
"SELECT 'Other Total' AS Area, Sum(Lnk_AreaPicks.OtherT) AS Total" & _
"FROM Lnk_AreaPicks" & _
"GROUP BY 'Other Total'"
DoCmd.SetWarnings True
DoCmd.Close
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
Thanks in advance, Tadynn