Project

General

Profile

Backport #2947

win32ole & MS Access 2007

Added by plang (Philippe Lang) over 9 years ago. Updated 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
[ruby-core:28580]

Description

=begin
Hi,

When opening a MS Access database with ruby code like


require 'win32ole'
access = WIN32OLE.new('Access.Application')
database = File.expand_path('db2000.mdb')
access.OpenCurrentDatabase(database, false)
access.DoCmd.OpenReport("rptTest")
access.Visible = true


... database is opened read-write with MS Access 2000/2003, and read-only with MS Access 2007.

I have made tests under Window 7 with ruby 1.8.6 patchlevel 111 and patchlevel 398.

Database format is not an issue: the same problem happens with a database in 2000 (mdb) or 2007 (accdb) format.

I'm not sure if that's a ruby bug or a MS Access limitation, but vbs code like


Set objAcc = WScript.CreateObject("Access.Application")
strDBName = "C:\Users\Philippe Lang\Desktop\db2000.mdb"
objAcc.OpenCurrentDatabase strDBName
objAcc.run "get_document_lines_store", "1234", "L", "1"
objAcc.DoCmd.OpenReport "rptTest", 2, "", ""
objAcc.Visible = true


... opens the database read-write, whatever version of MS Access we use.
=end


Files

win32ole.jpg (144 KB) win32ole.jpg Database marked as opened read-only. plang (Philippe Lang), 03/10/2010 12:09 AM

History

#1

Updated by plang (Philippe Lang) over 9 years ago

=begin
Problem found: until Access 2007, path to the database can be specified with slashes or backslashes. It works in both situations. Since Access 2007, slashes yield to a read-only database, and backslashed a read-write database. Strange, but true!

Since expand_path expands the path of a file with slashes, code had to be slightly changed in order to work with Access 2007:


require 'win32ole'
access = WIN32OLE.new('Access.Application')
database = File.expand_path('db2000.mdb').gsub(/\//, '\')
access.OpenCurrentDatabase(database, false)
access.DoCmd.OpenReport("rptTest")
access.Visible = true


Note that the vbs code has the same symptoms: if backslashes are replaced with slashes, database is opened read-only.


Set objAcc = WScript.CreateObject("Access.Application")
strDBName = "C:/Users/Philippe Lang/Desktop/db2000.mdb"
objAcc.OpenCurrentDatabase strDBName
objAcc.run "get_document_lines_store", "1234", "L", "1"
objAcc.DoCmd.OpenReport "rptTest", 2, "", ""
objAcc.Visible = true


This is the case for native Access 2007 databases, and Access 2000 database in "compatibility mode" under Access 2007.

Hope it can help anyone. Case can be closed.
=end

#2

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

  • ruby -v deleted (ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32] or ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] )
  • Target version deleted (Ruby 1.8.6)
  • Status changed from Open to Closed
  • Description updated (diff)
  • Project changed from Ruby 1.8 to Backport187
  • Tracker changed from Bug to Backport

Also available in: Atom PDF