# WIN32OLE & MS Access 2007: read-only... only?

**URL:** <https://www.ruby-forum.com/t/win32ole-ms-access-2007-read-only-only/184121>\
**Category:** Ruby\
**Created:** [February 25, 2010, 1:41pm UTC](https://www.ruby-forum.com/t/win32ole-ms-access-2007-read-only-only/184121 "2010-02-25T13:41:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [February 25, 2010, 1:41pm UTC](https://www.ruby-forum.com/t/win32ole-ms-access-2007-read-only-only/184121/1 "2010-02-25T13:41:37Z")

</div>

Hi,

With Office 2003, I am able to open through ruby an Access database,  
make a few structure changes in it, and finally open a report, with code  
similar to:

require ‘win32ole’  
access = WIN32OLE.new(‘Access.Application’)  
database = File.expand\_path(’\<the\_msaccess\_database\_name\>)  
access.OpenCurrentDatabase(database)  
access.run("\<the\_msaccess\_public\_sub\_in\_vbs\>", “param1”, “param2”)  
access.DoCmd.OpenReport(“the\_msaccess\_report”, 2, “”, “”)  
access.Visible = true

This works fine with both the old Ruby O.-Click Installer 1.8.6, and  
the upcoming Ruby Installer 1.8.6 RC2, from Luis L…

Unfortunately, things are getting worse with Office 2007. For an unknown  
reason, database is opened _read-only_, and the command

access.run("\<the\_msaccess\_public\_sub\_in\_vbs\>", “param1”, “param2”)

… fails, since it tries to modify the structure (a querydef in fact)  
of a read-only database.

Strangely, this almost similar code rewritten in wsh:

Set objAcc = WScript.CreateObject(“Access.Application”)  
strDBName = “\<the\_msaccess\_database\_path\>”  
objAcc.OpenCurrentDatabase strDBName  
objAcc.run “\<the\_msaccess\_public\_sub\_in\_vbs\>”, ", “param1”, “param2”  
objAcc.DoCmd.OpenReport “the\_msaccess\_report”, 2, “”, “”  
objAcc.Visible = true

… works perfectly. Access 2007 database is opened read-write, and  
scripts executes fine.

I’m not sure who is the culprit here: Ruby/WIN32OLE? Not really, it  
works fine with Office 2003. Office 2007? Hum, maybe, but it works  
through WSH…

Does anyone have an idea maybe?

Best regards,

---

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [February 25, 2010, 2:39pm UTC](https://www.ruby-forum.com/t/win32ole-ms-access-2007-read-only-only/184121/2 "2010-02-25T14:39:33Z")

</div>

> access.run("\<the\_msaccess\_public\_sub\_in\_vbs\>", “param1”, “param2”)
> 
> objAcc.Visible = true
> 
> … works perfectly. Access 2007 database is opened read-write, and  
> scripts executes fine.
> 
> I’m not sure who is the culprit here: Ruby/WIN32OLE? Not really, it  
> works fine with Office 2003. Office 2007? Hum, maybe, but it works  
> through WSH…
> 
> Does anyone have an idea maybe?

One more precision: with this VBScript code, integrated into an HTML  
file, database is opened read-write too. Only the ruby code opens the  
database read-only…
