Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: Ms Access and win32 ole

by sumit07 (Novice)
on Oct 26, 2012 at 10:43 UTC ( #1001041=note: print w/replies, xml ) Need Help??

in reply to Re: Ms Access and win32 ole
in thread Ms Access and win32 ole

Hi Sinistral

I am now trying to open using this code
$oDatabase = $oAccess->DBEngine->OpenCurrentDatabase($filename);
It says invalid argument.Do we need to provide other arguments also.

With this code $oDatabase = $oAccess->DBEngine->OpenDatabase($filename);

It opens fine but the custom properties doesnot get added to the file's custom tab in the database properties.
Is there any difference between OpenDatabase and OpenCurrentDatabase.
my $filename = 'C:\Documents and Settings\551970\Desktop\database.accd +b'; # $ARGV[0]; print $filename."\n"; $oAccess = Win32::OLE->new('Access.Application') or die qq{Couldn't st +art new Access instance!}; # Open Access File $oDatabase = $oAccess->DBEngine->OpenDatabase($filename); my $new_property = $oDatabase->Containers->Databases->Documents->User +Defined->CreateProperty("Test1",12,"Test"); $oDatabase->Containers->Databases->Documents->UserDefined->Propertie +s->Append($new_property); foreach (in $oDatabase->Containers->Databases->Documents->UserDefined- +>Properties) { #print Dumper($_); print "prop ".$_->Name."\n"; } undef $oDatabase; #undef $oAccess; $oAccess->Quit();

Replies are listed 'Best First'.
Re^3: Ms Access and win32 ole
by Sinistral (Monsignor) on Oct 26, 2012 at 13:50 UTC

    Most of my Win32::OLE experience has been with Excel, not Access, but a little Googling found this link: which specifically says that OpenCurrenDatabase is for manipulating Access and opening files, while OpenDatabase returns a Database variable but doesn't actually open the file in the Access window. So for you, you want OpenCurrentDatabse. Beyond that, the best thing I can offer is to check out the documents I linked to, which are the Automation docs for Access 2007 (switch to 2010 if that's what you're using).

    The other tip I've seen is to record a macro of the task you're trying to achieve and examine the VBA code that Access creates. It looks like you're on your way already to knowing the Perl Win32::OLE to VBA equivalent

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1001041]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2023-06-09 11:50 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (35 votes). Check out past polls.