Connect a database (MDB) to excel

Last update on February 19, 2009 10:17 AM by deri58
Published by deri58

[VBA] Connecting a database (MDB) to excel








Below is a tips of how to connect an Access database (MDB) in an application excel
Add reference
Microsoft DAO object librairy X.X


In a general module (eg Module1) paste the code below

<ital>Sub CopieDBaccess ()
Sunday BDexp As Database
Sunday Table As Recordset
As Sunday TbDef TableDef
Sunday Ch As String, Lig As Long, i As Integer, Name (4) As String
Ch = "& path \ & NomDeLaBD.MDB"
Set BDexp = DBEngine.Workspaces (0). OpenDatabase (Ch)
Set Table = BDexp.OpenRecordset ( "tablename", dbOpenDynaset)
'Debug.Print Table.Name
Set TbDef = BDexp.TableDefs ( "companydetails")
Lig = 3
'Place the column
With Sheets ( "Sheet1")
For i = 0 To TbDef.Fields.Count - 1 'For any line
'Debug.Print TbDef.Fields (i). Name
Name (i) = TbDef.Fields (i). Name
. Cells (Lig, i + 3) = Name (i)
Next
'Caller registration on 1
Table.MoveFirst
Lig = 4
While Not Table.EOF
For i = 0 To TbDef.Fields.Count - 1 'For any line
. Cells (Lig, i + 3) = Table (Name (i))
Next i
Lig Lig + 1 =
Table.MoveNext 'move to the next record
Wend
End widt
Table.Close
BDexp.Close
Set BDexp = Nothing
Set Table = Nothing
Best answers for « Connect a database (MDB) to excel » in :
Connecting to an Ingres database with PHP Show Connecting to an Ingres database with PHP Getting started Download PECL Installation Windows Linux & Unix Getting connected This tip is based on following Ingres documentation: Getting started Ingres® 2006 Release 2 for...
Visual FoxPro and SQL Server ShowVisual FoxPro and SQL Server Visual Foxpro 9 and SQL Server 2005 Is there a better alternative than using Visual FoxPro to manage efficiently a SQL Server? Here's an interesting issue. For more information see the article:...
Connecting to Oracle via php ShowConnecting to Oracle via php Settings Requirements Example of code Settings Below is an article based on an example of connection to an Oracle database through a php script. However it is not designed to configure your oracle...
Error code 81000303 - Connection Problem ShowError code 81000303 - Connection Problem MSN connection problem First Solution Alternative MSN connection problem Check the status of MSN Messenger servers to determine if the problem does not come from there before any changes on...
Download Bulk Email Sender ShowWith Bulk Email Sender you can send mass messages in html. You can use the original templates or create your own for re-use later. Advantage It is possible to import a list of addresses from a database, an Excel file, a text file or type all the...
ODBC ShowWhat is ODBC? ODBC stands for Open Database Connectivity. This is a Microsoft-defined format for communicating between Windows database clients and consumer DBMSs. The ODBC managier can be found in Windows 3.1 and 9x. In Windows 95 and 98, it is...
Sharing an Internet connection ShowAdvantages If you have a local area network (two or more computers connected in a network) with one computer connected to the Internet (via a modem, using a cable, etc.), it may be useful to make the connection accessible to the other computers on...
Sharing an Internet connection in Windows XP ShowAdvantages If you have a local area network (two or more computers connected in a network) with one computer connected to the Internet (via a modem, using a cable, etc.), it may be useful to make the Internet accessible to the other computers on...