TransferSpreadsheet Fails Within Transaction?

P

PeteCresswell

When I try DoCmd.TransferSpreadsheet within a transaction, it fails
with "3008: The table 'xxxx' is already opened exclusively by another
user, or it is already open through the user interface and cannot be
manipulated programmatically."

But when I rem out the .OpenTrans/.CommitTrans lines it works A-OK.

I'm doing something dumb.... but what?

Code:
------------------------------------------------------------------------------------
Private Sub cmdImportKLD_Click()
2000 debugStackPush Me.Name & ": cmdImportKLD_Click"
2001 On Error GoTo cmdImportKLD_Click_err

' PURPOSE: To completely replace the contents of
tbl_SEI_KLDExclusionary
' with whatever is in a spreadsheet received from KLD
Research & Analytics
'

2002 Dim thisWS As DAO.Workspace

Dim k As Long
Dim myPath As String
Dim transOpen As Boolean
Dim myStartingDir As String

Const myParmName As String = "KldExclusionaryDir"


2010 myStartingDir = IniValue_Get(gProgramParms, myParmName)

2020 If Len(myStartingDir) = 0 Then
2021 myStartingDir = DesktopPath_Get()
2029 End If

2030 myPath = CommonFileDialog_Open("Choose The 'SL FUND FRN RESET'
Workbook To Import From:", myStartingDir, "", "xls", "Excel
Spreadsheets", False)
2039 myPath = TrimTrailingNulls(myPath)

2040 If DirExist(myPath) = False Then
2041 MsgBox "You did not choose a spreadsheet", vbExclamation,
"Import Cancelled"
2049 Else
2050 Set thisWS = DBEngine(0)
'2051 thisWS.BeginTrans
2059 transOpen = True

' ---------------------------------------
' Get rid of what's there now

2060 CurrentDb.Execute "qryProscribedCompanies_Purge",
dbFailOnError
2069 DoEvents

' ---------------------------------------
' Import new values

2070 DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"tbl_SEI_KLDExclusionary", myPath, True

' ---------------------------------------
' If nothing abended, save the new values
' and squirrel away the starting directory
' for next time

'2080 thisWS.CommitTrans
2089 transOpen = False

2090 myStartingDir = ExtractDirPath(myPath)
2099 IniValue_Put gProgramParms, myParmName, myStartingDir

2990 MsgBox "The new KLD values have been imported.",
vbInformation, "Done!"
2999 End If

cmdImportKLD_Click_xit:
DebugStackPop
On Error Resume Next
Set thisWS = Nothing
Exit Sub

cmdImportKLD_Click_err:
If transOpen = True Then
thisWS.Rollback
transOpen = False
End If

BugAlert True, ""
Resume cmdImportKLD_Click_xit
End Sub
------------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top