i'm looking for a way to communicate from Access to Project.
I know that i can export a planning from Project to a MDB file but without knowing which fields ( and there are many ) to edit it is not possible to import it back into Access.
In code, you can “Reference” the Project Object Library. Once you have it referenced, you can create one or more object variables that reference Project and essentially use project through code.
To make the reference, open a code window and select Tool, References. Scroll through the list and check the Project Object Library, then click ok.
To see what commands are available, select View, Object Library and select the MSProject library.
The setup for the object variable is typically similar to:
Sub OpenProject(strFileName As String)
Dim objProject As MSProject.Application
On Error Resume Next
AppActivate ("Microsoft Project") ' This activates Project if it's open, otherwise it generates an error
If Err Then ' This catches the error if project wasn't open
Err.Clear ' This clears the error
On Error GoTo 0 ' This turns off error trapping (so that a genuine error is generated if Project isn't found
Set objProject = CreateObject("MSProject.Application") ' This launches Project and assigns it to the variable
On Error GoTo 0
Set objProject = GetObject(, "MSProject.Application") ' This assigns project to the variable
objProject.Visible = True ' This make project visible (just in case it open hidden by default)
objProject.FileOpen strFileName ' This opens a file
Set objProject = Nothing ' This release Project from the variable. Note: this leaves project open
It will take a little while to navigate through the list of commands, actions and properties. A good way to get started is to write a Macro in Project and then view the code – the command structure inside Access will be EXACTLY THE SAME with the exception of placing your object variable in front of each Project command.
1. ALWAYS set your object variables equal to nothing (note the last line of code before the End Sub). Although Microsoft is supposed to clear the memory associated with the variable, it’s a documented place that “Memory Leaks” can occur.
2. If the program is loaded on a machine that either doesn’t have Project or has an older version, you will get an error on the first piece of code Access tries to run – the error won’t specifically be related to the Project library. If one reference fails, they ALL fail.