Bonediggler
Technical User
Hi--
When trying to use a loop to import multiple worksheets from a workbook, I get run time error 3051: "MS Jet Engine cannot open (string)...it is already open by another user or you need permission to view its data."
The file in question is neither in use by another user or password-protected. The code is as follows:
Private Sub cmdMultipleSheets_Click()
Dim SheetName As String
Dim sFullPath As String
Dim FileToUse As String
Dim r As Integer
Dim Day1 As Integer
Dim DayEnd As Integer
Dim Month As String
sFullPath = "Path Details" & FileToUse
Day1 = Right(txtValues.Value, 2)
DayEnd = Right(txtValues2.Value, 2)
Month = Left(txtValues.Value, 3)
For r = Day1 To DayEnd
SheetName = Month & " " & r & "!"
FileToUse = Combo26.Value
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "tbl_Blah", sFullPath, -1, SheetName
Next r
ExitLine:
Exit Sub
End Sub
When trying to use a loop to import multiple worksheets from a workbook, I get run time error 3051: "MS Jet Engine cannot open (string)...it is already open by another user or you need permission to view its data."
The file in question is neither in use by another user or password-protected. The code is as follows:
Private Sub cmdMultipleSheets_Click()
Dim SheetName As String
Dim sFullPath As String
Dim FileToUse As String
Dim r As Integer
Dim Day1 As Integer
Dim DayEnd As Integer
Dim Month As String
sFullPath = "Path Details" & FileToUse
Day1 = Right(txtValues.Value, 2)
DayEnd = Right(txtValues2.Value, 2)
Month = Left(txtValues.Value, 3)
For r = Day1 To DayEnd
SheetName = Month & " " & r & "!"
FileToUse = Combo26.Value
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "tbl_Blah", sFullPath, -1, SheetName
Next r
ExitLine:
Exit Sub
End Sub