get an mdb table record using vbscript

Posted on 2013-12-10
Medium Priority
Last Modified: 2013-12-15
#1) How can I get the following code to run under vbs? It already works under vba, but under vbscript I get the error message

               provider cannot be found. It may not be properly installed

#2) How can I get it to use DAO instead of ADO?   (this is not too important, but I would like to know for future projects.)

The code must run on Windows 7 computers with Office 2010 home and business, They  do NOT have MS Access installed.  

Const path = "C:\Users\bob.berke\Documents\db1.mdb"
const custno = 1234567
sql = "select folder from table2 where cust = " & custno 

Set objconnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objconnection.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & path

objRecordSet.Open sql, objconnection
MsgBox objRecordSet(0)

Open in new window

--- some background details, but they are not very important   --------
I have modified the windows explorer context menu for our small business client computers.

When users right click on a file named  "Client #1234 has not received their order" the users see the normal windows commands like "open", "delete"  and one additional command :
         "GOTO client's master folder"

When the user chooses that GOTO option, the vbs program grabs the filename, scans for the client number, then opens the directory associated with the order.

Right now, the client numbers are hard coded in the vbs, but that is a temporary workaround until I figure out how to get the data from the database.
Question by:rberke
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
  • 6
  • 3
LVL 32

Expert Comment

by:Daniel Wilson
ID: 39708600
Microsoft Jet is not installed.  You need to download and install it.  

I don't think you will need to install the MS Access Runtime.  It is free with Visual Studio Professional ... maybe other packages as well ... but for merely accessing the DB via Jet it should not be needed.
LVL 32

Expert Comment

by:Daniel Wilson
ID: 39708606
Here, this should be what you need to download & install.

Author Comment

ID: 39709280
I have 10 computers that will need it, and I am a little lazy about installing software on all 10 computers.

All 10 of those programs already have Vba applications that merrily read mdb tables with DAO under Excel, Word, and Outlook.

Isn't there some way to do the same thing with vbscript without installing new software?

For instance, perhaps vba is using a different provider? If so, I could browse the object using excel's IDE and find the right name to use?

Also, that code specifying Microsoft.Jet.OLEDB.4.0 works under vba. Doesn't that sort of imply that the jet engine is already installed?

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.


Author Comment

ID: 39709442
I forgot to mention all the Windows 7 machines are using 64 bit Windows 7.

I found this reference which is interesting http://stackoverflow.com/questions/15069440/accessing-mdb-through-vbs

When I invoke the program using the windows 32 bit compatibility code, things work fine !!!

      c:\windows\syswow64\wscript "C:\Users\bob.berke\Desktop\test4.vbs"

So, as a "solution" I can make my right click context menu program call a .bat file that calls the vbs program.  Bu that is really ugly.  

Can anybody suggest a cleaner way?  Maybe vbscript has a compiler directive that tells it to run in 64bit mode?

Accepted Solution

rberke earned 0 total points
ID: 39709510
Windows is a 4 letter word  !!!!

It appears that this is a common problem which can be fixed with the code at http://stackoverflow.com/questions/2806584/how-do-i-run-a-vbscript-in-32-bit-mode-on-a-64-bit-machine

I followed the instructions and it worked perfectly.  I copied the code to the clipboard,
then pasted it with no changes above my first line.

After that my vbs worked fine.  Ugly as sin, but it worked fine.  There are simpler versions of the code available elsewhere, but this is the first version I found that allows the .vbs program to be called with multiple arguments.


So, I answered my question #1 myself.  I will still give points to anybody that tells me how to switch my code to use DAO instead of ADO.
LVL 32

Assisted Solution

by:Daniel Wilson
Daniel Wilson earned 1000 total points
ID: 39709920
LVL 38

Assisted Solution

PatHartman earned 1000 total points
ID: 39709951
DAO is extremely obsolete.
I don't think so - it is the default for A2013 and is alive and well.  Since A2007 and the advent of ACE (replacement for Jet), DAO has been under the control of the Access development team rather than the SQL Server team who kept trying to kill Jet and spreading rumors of its demise.  But instead of saying we are killing Jet, they kept telling people that they were killing Access.

It is ADO that is losing support -

Assisted Solution

rberke earned 0 total points
ID: 39710182
That link dd not convince me that DAO is on the rebound, but that doesn't matter.

I'll stop using DAO when it stops working and not until then.

But, I really don't have a strong preference for either, its just that I have a bunch of old code that uses DAO, and I don't have a good business reason to change it.  

But, the vbscript environment is radically different than the VBA environment, and the program is now working well with ADO, so I think this particular program will stay in ADO.

Thanks for your help.

Author Comment

ID: 39713007
In response to the administrative comment about the link policy, I have redrafted the "correct answer" as follows.

I have a 5 line vbscript program that fails.

When a user double clicks on FiveLines.vbs, Windows 64bit launches a 64bit command processor. Unfortuantely, that processor is not able to handle ADO and similar database functions so it displays an error message.

Luckily, Windows 64bit also ships with a 32bit command processor that CAN handle those functions.

It can be executed from a batch file as follows

  c:\windows\syswow64\wscript “fivelines.vbs”

But, since my program must be run from a windows explorer context menu, that might not work.

Instead, I added a chunk of extra code above the original 5 lines. The added chunk does the  following
1) If the 32bit command processor is running, transfer to the 5 lines of code
2) if the 64bit command processor is running, create a new command line string, and shell to it using the syswow64 version of wscript.

The bad news is that this takes about 60 lines of obscure coding.  The good news is I found the exact code needed here.  I just copied the code to the clipboard and pasted it in front of my code. Problem solved

Author Closing Comment

ID: 39719767
The experts comments are interesting so they both get points, but I found the code that made things work on my own with no help for either expert.

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

765 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