Solved

Excel file as ADODB says Read Only

Posted on 2014-01-09
4
1,424 Views
Last Modified: 2014-01-23
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

0
Comment
Question by:versatilebb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 18

Expert Comment

by:x-men
ID: 39771361
"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?
0
 

Author Comment

by:versatilebb
ID: 39772556
I did reboot and the problem persists.    Any other suggestions?  Is my syntax otherwise in good shape?

Thanks
0
 

Accepted Solution

by:
versatilebb earned 0 total points
ID: 39791420
I finally realized what was going on here.  I had my installer put files in the "Program Files" folder.  Then when my code tried to update the file there, it was not allowing me to write to that location.  Solution is to keep all files you need to write to in the user's AppData area.
0
 

Author Closing Comment

by:versatilebb
ID: 39802533
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.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question