Create a macro to open a MS access database

C

clair69

Hello Everyone,

I would like create a macro Using MS Outlook 2003 that will open a MS Access
datebase and I am not sure how to write this.

can anyone help?
 
K

Ken Slovak - [MVP - Outlook]

How do you want to talk to the Access database, DAO or ADO or pure Access
code or what?

For DAO:

Dim dbEmployees As DAO.Database
Dim rstEmployees As DAO.Recordset

Set dbEmployees = OpenDatabase _
("C:\Program Files\Microsoft " _
& "Office\Office\Samples\Northwind.mdb")

' Use an SQL statement to get the data from the Employees
' table into a recordset.
Set rstEmployees = dbEmployees.OpenRecordset _
("SELECT FirstName, LastName, Address, City, " _
& "Region, PostalCode, Country, " _
& "HomePhone FROM Employees;")

For ADO:

Dim m_Conn As ADODB.Connection
Dim oRec As ADODB.Recordset

Set m_Conn = New ADODB.Connection
m_Conn.Provider = "Microsoft.Jet.OLEDB.4.0" 'using an MDB file

'm_Conn.Provider = "Microsoft.ACE.OLEDB.12.0" 'using an ACCDB file

'Open a Connection to the Database
m_Conn.Open "C:\Pro_Outlook\Northwind.mdb"
'm_Conn.Open "C:\Pro_Outlook\Northwind 2007.accdb"

If m_Conn.State = adStateOpen Then
Set oRec = New ADODB.Recordset

'Build the Select Statement
sSql = "SELECT [First Name], [Last Name] FROM Employees " _
& "WHERE [Job Title] = 'Sales Representative';"

'Open the Recordset
oRec.Open sSql, m_Conn, adOpenForwardOnly

And so on.
 
Top