ebaltas
May 22nd, 2001, 02:02 PM
I'm trying to import a series of excel spreadsheets while also running some queries to delete any uneeded rows in the spreadsheets. I can't see to to get the following code to properly work. Any help someone can provide me would be greatly appreciated:
Private Sub Command5_Click()
Dim svy_impt_path
Dim filename
Dim counter As Integer
svy_impt_path = InputBox("Enter the path in which the survey results files are" & _
" located." & Chr(13) & Chr(13) & "Example: c:\abc\surveys\", "Import Survey Results")
If svy_impt_path = "" Then
MsgBox "Operation Canceled."
Exit Sub
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "Clear Imported Survey Results Tbl"
DoCmd.OpenQuery "Clear Location and Customer Svy Tbl"
filename = Dir(svy_impt_path & "*.xl*") ' Retrieve the first entry.
Do While filename <> "" ' Start the loop.
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "Imported Survey Results", _
svy_impt_path & filename, True, "'Activity Survey'!d2:g"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "Location and Customer Survey Results", _
svy_impt_path & filename, True, "'Location and Customer Survey'!b2:e"
filename = Dir
Loop
DoCmd.OpenQuery "Remove Rows in Act Svy that do not have percentages"
DoCmd.OpenQuery "Remove Rows in Act Svy that do not have acts"
DoCmd.OpenQuery "Remove Rows in L&C Svy that do not have percentages"
DoCmd.OpenQuery "Remove Rows in L&C Svy that do not have loc"
DoCmd.OpenQuery "Clear Imported_Survey_Results Tbl"
DoCmd.OpenQuery "Apd I S R to I_S_R tbl"
DoCmd.OpenQuery "Change 8s to 8-1"
DoCmd.OpenQuery "Clear Cost Object_Svy_Results Tbl"
DoCmd.OpenQuery "Apd L&C to C Obj_Svy_Res Tbl"
'Delete Import Error Tables
On Error GoTo ErrorHandler
DoCmd.DeleteObject acTable, "e_ImportErrors"
DoCmd.DeleteObject acTable, "g_ImportErrors"
For counter = 1 To 100
DoCmd.DeleteObject acTable, "e_ImportErrors" & counter
DoCmd.DeleteObject acTable, "g_ImportErrors" & counter
Next
ErrorHandler:
Select Case Err.Number
Case 3011
Resume Next
End Select
DoCmd.SetWarnings True
MsgBox "Survey results have been imported and compiled.", , "Model Message"
End Sub
Private Sub Command5_Click()
Dim svy_impt_path
Dim filename
Dim counter As Integer
svy_impt_path = InputBox("Enter the path in which the survey results files are" & _
" located." & Chr(13) & Chr(13) & "Example: c:\abc\surveys\", "Import Survey Results")
If svy_impt_path = "" Then
MsgBox "Operation Canceled."
Exit Sub
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "Clear Imported Survey Results Tbl"
DoCmd.OpenQuery "Clear Location and Customer Svy Tbl"
filename = Dir(svy_impt_path & "*.xl*") ' Retrieve the first entry.
Do While filename <> "" ' Start the loop.
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "Imported Survey Results", _
svy_impt_path & filename, True, "'Activity Survey'!d2:g"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "Location and Customer Survey Results", _
svy_impt_path & filename, True, "'Location and Customer Survey'!b2:e"
filename = Dir
Loop
DoCmd.OpenQuery "Remove Rows in Act Svy that do not have percentages"
DoCmd.OpenQuery "Remove Rows in Act Svy that do not have acts"
DoCmd.OpenQuery "Remove Rows in L&C Svy that do not have percentages"
DoCmd.OpenQuery "Remove Rows in L&C Svy that do not have loc"
DoCmd.OpenQuery "Clear Imported_Survey_Results Tbl"
DoCmd.OpenQuery "Apd I S R to I_S_R tbl"
DoCmd.OpenQuery "Change 8s to 8-1"
DoCmd.OpenQuery "Clear Cost Object_Svy_Results Tbl"
DoCmd.OpenQuery "Apd L&C to C Obj_Svy_Res Tbl"
'Delete Import Error Tables
On Error GoTo ErrorHandler
DoCmd.DeleteObject acTable, "e_ImportErrors"
DoCmd.DeleteObject acTable, "g_ImportErrors"
For counter = 1 To 100
DoCmd.DeleteObject acTable, "e_ImportErrors" & counter
DoCmd.DeleteObject acTable, "g_ImportErrors" & counter
Next
ErrorHandler:
Select Case Err.Number
Case 3011
Resume Next
End Select
DoCmd.SetWarnings True
MsgBox "Survey results have been imported and compiled.", , "Model Message"
End Sub