Avatar of Bryce Bassett
Bryce Bassett
Flag for United States of America asked on

Excel file as ADODB says Read Only

Hi

Working in Word 2010 VBA.  using the method below to read from, and in this case, write to an Excel file using ADODB.  I've used this method countless times with no problem.  But tonight all of a sudden when I reaches the objRecSet.AddNew command, it gives me the error message "Cannot update.  Database or object is read only."  The Excel file is not read only, is not open in Excel, and was properly shut down by my last ADOBD routine.  

What could be causing this?

Set objConnection = New ADODB.Connection
objConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DataFile & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=0"";"  'HDR=YES means has col headings
objConnection.Open
Set objRecSet = New ADODB.Recordset

objRecSet.Open TableName, objConnection, adOpenKeyset, adLockOptimistic 

    For myrow = 0 To SaveSystem.ListBox3.ListCount - 1
        objRecSet.AddNew
        objRecSet.Fields(0) = Me.TextBox1.Text
        For mycol = 0 To 4
            objRecSet.Fields(mycol + 1) = SaveSystem.ListBox3.List(myrow, mycol)
        Next mycol
    Next myrow

objRecSet.UpdateBatch
     
objRecSet.Close
objConnection.Close
Set objRecSet = Nothing
Set objConnection = Nothing

Open in new window

Microsoft ApplicationsMicrosoft ExcelMicrosoft Word

Avatar of undefined
Last Comment
Bryce Bassett

8/22/2022 - Mon
x-men

"The Excel file is not read only, is not open in Excel, and was properly shut down by my last ADOBD routine.  "...still, sounds like it is in use, some how. can you reboot?
Bryce Bassett

ASKER
I did reboot and the problem persists.    Any other suggestions?  Is my syntax otherwise in good shape?

Thanks
ASKER CERTIFIED SOLUTION
Bryce Bassett

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bryce Bassett

ASKER
This wasn't really an issue with the code itself, but the installation environment.  Not fair to expect the experts to know what was going on with that.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck