Solved

How to use VB to execute Access File?

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

707 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

22 Experts available now in Live!

Get 1:1 Help Now