Solved

How to use VB to execute Access File?

Posted on 2004-04-10
5
1,107 Views
Last Modified: 2012-08-13
I have develop a system in Ms Access. Now, I would like to use VB to write codes to exceute the Ms Access file. I know the Shell can execute the EXE file, but how about executing a mdb file? Pls help. Thanks.
0
Comment
Question by:Kelvsat
5 Comments
 
LVL 6

Expert Comment

by:PhilAI
ID: 10796433
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10796511
you do NOT 'execute' an MDB file.  You use your VB program to read the data from the tables, and to write data back to the tables, or to use the Queries in the Database.

PhilAI is way off base, as the Shell function has NBOTHING whatsoever to do with using an Access MDB from a VB program.

In you VB Program, you can use either of two Data Access Technologies:

DAO - Data Access Objects, uses the JET engine, and is design for use with Access Databases, but is OLDER and 'obsolete' technology.  Microsoft is phasing OUT the on going support for DAO

ADO - ActiveX Data Objects - Uses OLEDB to connect to almost ANY data source (including Access), is the newest technology, and is Microsoft's approach to Universal Data Access.

With ADO: (Add a REFERENCE to the ActiveX Data Library - Project/References)

    Dim cn as ADODB.Connection
    Dim rs as ADODB.Recordset
    Dim strSQL as String

    Set cn = New ADODB.Connection
    cn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<Path to your database>;"
    cn.Open

    strSQL = "Select * from YourTable"

    set rs = cn.Execute(strSQL)

as a simple Example of getting data from a Table in an Access Database.

AW
   
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10796632
Hi Kelvsat,

Don't hesitate, go with Arthur_Wood. He is absolutely %100 correct. And don't touch DAO, go with ADO.

S
0
 
LVL 6

Accepted Solution

by:
PhilAI earned 125 total points
ID: 10797769
Declaration:

Private Declare Function ShellExecute Lib "shell32" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

How to use,

0& can be Me.Hwnd if you are using the function in a form

Call ShellExecute(0&, "open", "E:\database\MHclients.mdb", "", "", 3)


This uses the file association with MDB to open the file in MS Access
0
 
LVL 35

Expert Comment

by:Bembi
ID: 10798358
You question is a little bit unclear, but one of the comments above should give you the hint.

Let me add, that you can do everything with a MDB file without any need for Access itself. VB uses the MS JET Engine or ADO (newer) to control a Access database. So you can create / delete any object (tables, queris), read / write any data, add / delete users and so on. No need for Access as shell. The only exceptions it, that you do not have access to the Access forms or reports without opening Access. But you can replace this by VB Forms and the included report designer of VB.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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