ADO connecting to a .mpp file or similar

G

Guest

Hello,
In previous work with Microsoft Excel, I could make a direct ADO connection
to a .xls file as if it were a database. Can you do similar things with a
..mpp? or must I save as a database format first and then connect?

Thanks,
Dan
 
G

Gérard Ducouret

Hello,
Yes, you can. Please find a sample of such a connection.
NB : you need to create a reference on Microsoft ActiveX Data Objects 2.1
Library : Tools / Reference

Hope this helps,

Gérard Ducouret [Project MVP]
PragmaSoft ® - Paris

Sub ConnectLocally()
Dim conData As New ADODB.Connection
Dim rstAssigns As New ADODB.Recordset
Dim intCount As Integer
Dim strSelect As String
Dim strResults As String
Dim FILE_NAME As String

FILE_NAME = "C:\Mes Documents\MS Project 2K\StockProjets\Projet B.mpp"

conData.ConnectionString = "Provider=Microsoft.Project.OLEDB.9.0;PROJECT
NAME=" & FILE_NAME
' To connect to a Microsoft SQL Server or Oracle Server file, you must also
supply User ID and Password arguments
' conData.ConnectionString = "Provider=Microsoft.Project.OLEDB.9.0;User
ID=jsmith;Password=MyPass5;PROJECT NAME=" & FILE_NAME

conData.ConnectionTimeout = 30
conData.Open

strSelect = "SELECT ResourceUniqueID, AssignmentResourceID,
AssignmentResourceName, TaskUniqueID, AssignmentTaskID, AssignmentTaskName
FROM Assignments WHERE TaskUniqueID > 0 ORDER BY AssignmentTaskID ASC"
rstAssigns.Open strSelect, conData

Do While Not rstAssigns.EOF
For intCount = 0 To rstAssigns.Fields.Count - 1
strResults = strResults & "'" & rstAssigns.Fields(intCount).Name
& "'" & _
Space(30 - Len(rstAssigns.Fields(intCount).Name)) & vbTab &
_
CStr(rstAssigns.Fields(intCount).Value) & vbCrLf
Next
strResults = strResults & vbCrLf
rstAssigns.MoveNext
Loop

conData.Close

Open "C:\Mes Documents\Results.txt" For Output As #1
Print #1, strResults
Close #1

Shell "Notepad C:\Mes Documents\Results.txt", vbMaximizedFocus

End Sub
 
D

DapperDanH

Thanks! Worked like a charm!

Dan

Gérard Ducouret said:
Hello,
Yes, you can. Please find a sample of such a connection.
NB : you need to create a reference on Microsoft ActiveX Data Objects 2.1
Library : Tools / Reference

Hope this helps,

Gérard Ducouret [Project MVP]
PragmaSoft ® - Paris

Sub ConnectLocally()
Dim conData As New ADODB.Connection
Dim rstAssigns As New ADODB.Recordset
Dim intCount As Integer
Dim strSelect As String
Dim strResults As String
Dim FILE_NAME As String

FILE_NAME = "C:\Mes Documents\MS Project 2K\StockProjets\Projet B.mpp"

conData.ConnectionString = "Provider=Microsoft.Project.OLEDB.9.0;PROJECT
NAME=" & FILE_NAME
' To connect to a Microsoft SQL Server or Oracle Server file, you must also
supply User ID and Password arguments
' conData.ConnectionString = "Provider=Microsoft.Project.OLEDB.9.0;User
ID=jsmith;Password=MyPass5;PROJECT NAME=" & FILE_NAME

conData.ConnectionTimeout = 30
conData.Open

strSelect = "SELECT ResourceUniqueID, AssignmentResourceID,
AssignmentResourceName, TaskUniqueID, AssignmentTaskID, AssignmentTaskName
FROM Assignments WHERE TaskUniqueID > 0 ORDER BY AssignmentTaskID ASC"
rstAssigns.Open strSelect, conData

Do While Not rstAssigns.EOF
For intCount = 0 To rstAssigns.Fields.Count - 1
strResults = strResults & "'" & rstAssigns.Fields(intCount).Name
& "'" & _
Space(30 - Len(rstAssigns.Fields(intCount).Name)) & vbTab &
_
CStr(rstAssigns.Fields(intCount).Value) & vbCrLf
Next
strResults = strResults & vbCrLf
rstAssigns.MoveNext
Loop

conData.Close

Open "C:\Mes Documents\Results.txt" For Output As #1
Print #1, strResults
Close #1

Shell "Notepad C:\Mes Documents\Results.txt", vbMaximizedFocus

End Sub

Hello,
In previous work with Microsoft Excel, I could make a direct ADO connection
to a .xls file as if it were a database. Can you do similar things with a
.mpp? or must I save as a database format first and then connect?

Thanks,
Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top