?
Solved

How to use VB to execute Access File?

Posted on 2004-04-10
5
Medium Priority
?
1,112 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 500 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
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…
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…
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

771 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