Solved

How to use VB to execute Access File?

Posted on 2004-04-10
5
1,106 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

939 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

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now