Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot Access File for TransferSpreadsheet

Status
Not open for further replies.

Bonediggler

Technical User
Sep 20, 2007
19
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top