Solved

How to use VB to execute Access File?

Posted on 2004-04-10
5
1,110 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
[X]
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
5 Comments
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

729 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