Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Opening files in MS Access

by naive (Novice)
on Jan 31, 2002 at 09:31 UTC ( [id://142395]=perlquestion: print w/replies, xml ) Need Help??

naive has asked for the wisdom of the Perl Monks concerning the following question:


Hi
sorry to bother you guys once again!
Has anyone tried opening files in MS Access automatically using Win32::OLE??Is it possible?? If so how do u suggest that i go about writing the programme?Anyone has any suggestions other than using Win32::OLE??
Any reply will be greatly appreciated.THks!

Replies are listed 'Best First'.
Re: Opening files in MS Access
by clemburg (Curate) on Jan 31, 2002 at 13:11 UTC

    Hm, I am not sure want you want here:

    1. Open a file with MS Access after you have found it somehow in a perl process - easy, just launch MS Access with the filename as argument by way of the system() function - or even just launch the file name by way of system("start $filename"), which should work if the extension for MS Access is configured normally on the machine in question.
    2. Open an MS Access file by OLE - last time I did this (long time ago), I used my ($obj) = Win32::OLE->GetObject($file); to get an OLE object in Perl.

    Hope to have helped ...

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

Setting up MS Access as an ODBC Data Source
by Jazz (Curate) on Jan 31, 2002 at 18:52 UTC

    Yes, it is possible to open MSAccess files, as clemburg noted. You can also add, edit, delete, and query records in your MSAccess dbs from your Perl program.

    Because MSAccess is an ODBC source, you can work with its files using Win32::ODBC in your program. Win32::ODBC is part of the libwin32 libraries in the Perl standard distribution.

    Set up ODBC (if needed), then add the specific database as an the ODBC source.

    To do this, go to your control panel and click "ODBC Data Sources". Under the User DSN tab, you should see something like "MS Access 2000 Database" and on the same line, "Microsoft Access Driver". If you do, you're good. If you don't, you'll need to install the additional ODBC drivers from your Win2k cd.

    After you've confirmed that that the Access Driver is installed, click "Add" (in the User DSN window), select the Access Driver, then click Finish. Now you're at the setup window. Enter a mnemonic data source name, a short description, then click "Select" and browse to the Access db. If the db is password protected, click "Advanced" and enter the u/p.

    At this point the db is registered as an ODBC source.

    In your program, use Win32::ODBC and from there, it's straight SQL statements to insert, delete, query, etc.. Docs for Win32::ODBC are here. Here's some sample code:

    use Win32::ODBC; my $db = Win32::ODBC->new('datasourcename'); # as defined in your ODBC + panel $db->Sql( "INSERT INTO tablename ( Field ) VALUES( 'text to insert' ) +); $db->Close();

    Win32::ODBC is part of the libwin32 libraries, so if ActivePerl is installed, it ought to be installed correctly already. But you may want to install a more current version if available, which you can do by using the ppm manager (ppm.bat in your perl directory) and typing install libwin32 at the prompt.

    Hope this helps,
    Jasmine

      ODBC is definitely the way to go but if you do use ODBC then go for the DBI version rather than the Win32 version. This will make life easier when you change database vendors.

      I would also recommend avoiding Memo fields whereever possible. Othwerwise you are going to have to connect to the Access database using OLE.
      Hi thks for all your reply.
      What I meant is that I have sorted some data and created a common separated file using perl.After which I want to open this particular file in MS Access through perl.
      I do not mean going into MS Access to delete/edit/add/query data that was already saved in MS Access.
Re: Opening files in MS Access
by talexb (Chancellor) on Jan 31, 2002 at 13:30 UTC
    If you'd searched on the site using "MS Access" you would have found a wealth of information. Search first, ask later.

    More effort, please.

    --t. alex

    "Of course, you realize that this means war." -- Bugs Bunny.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://142395]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-24 06:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found