Solved

Excel file as ADODB says Read Only

Posted on 2014-01-09
4
1,434 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:Bryce Bassett
[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:Bryce Bassett
ID: 39772556
I did reboot and the problem persists.    Any other suggestions?  Is my syntax otherwise in good shape?

Thanks
0
 

Accepted Solution

by:
Bryce Bassett 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:Bryce Bassett
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

734 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