A
Andy Thomas
I have some VBA run from MS Excel that will loop through sub projects
on a MS Project 2000 .mpp file, and opens a ADO recordset for the
tasks on a sub project.
The process will run OK until, at a random sub plan, the run time
error (ref as above) 'Invalid Table Name "Tasks"' is generated when
the the code tries to open the recordset. Previous posts have
indicated this could be to do with the SQL statement being used to
open the recordset, but I know this can't be the case as a recordset
can be opened up to the point the error occurs.
There doesn't seem to be any pattern to when the error is thrown
either - on occasions the process can run through succesfully, then at
other times the error will be generated.
Any help in understanding the cause would be appreciated.
Extracts of code are below;
======================================================================
Sub ProcessRecordset(prname as String)
Dim rsTasks As Object
Dim strLocalPlanName As String
Dim strSQL As String
'Set SQL statement for recordset containing tasks
strSQL = "SELECT
Project,TaskName,TaskOutlineNumber,TaskFinish,TaskText1,TaskNotes,"
strSQL = strSQL &
"TaskPercentComplete,TaskUniqueID,TaskText5,TaskText7,TaskFlag1,TaskFlag2,TaskFlag3,"
strSQL = strSQL &
"TaskFlag4,TaskText9,TaskText25,TaskText26,TaskText27,TaskText28,TaskText29,TaskSummary"
strSQL = strSQL & ",TaskOutlineLevel,
TaskStart,TaskOutlineLevel ,TaskOutlineLevel,TaskOutlineLevel,TaskDuration
FROM Tasks where TaskOutlineNumber <> '0'"
Set cnsubplan = cnplan(prjname)
Set rsTasks = CreateObject("adodb.recordset")
Call rsTasks.Open(strSQL, cnsubplan)
'Process recordset
rsTasks.Close
cnsubplan.Close
Set rsTasks = Nothing
Set cnsubplan = Nothing
End Sub
==========================================================
Public Function cnplan(strPlanname As String) As Object
'Sets up a connection to a plan
strConn = "Provider=Microsoft.Project.OLEDB." & strVersion & ";PROJECT
NAME=" & strPlanname
Set cnplan = CreateObject("adodb.connection")
cnplan.Open (strConn)
End Function
==========================================================
on a MS Project 2000 .mpp file, and opens a ADO recordset for the
tasks on a sub project.
The process will run OK until, at a random sub plan, the run time
error (ref as above) 'Invalid Table Name "Tasks"' is generated when
the the code tries to open the recordset. Previous posts have
indicated this could be to do with the SQL statement being used to
open the recordset, but I know this can't be the case as a recordset
can be opened up to the point the error occurs.
There doesn't seem to be any pattern to when the error is thrown
either - on occasions the process can run through succesfully, then at
other times the error will be generated.
Any help in understanding the cause would be appreciated.
Extracts of code are below;
======================================================================
Sub ProcessRecordset(prname as String)
Dim rsTasks As Object
Dim strLocalPlanName As String
Dim strSQL As String
'Set SQL statement for recordset containing tasks
strSQL = "SELECT
Project,TaskName,TaskOutlineNumber,TaskFinish,TaskText1,TaskNotes,"
strSQL = strSQL &
"TaskPercentComplete,TaskUniqueID,TaskText5,TaskText7,TaskFlag1,TaskFlag2,TaskFlag3,"
strSQL = strSQL &
"TaskFlag4,TaskText9,TaskText25,TaskText26,TaskText27,TaskText28,TaskText29,TaskSummary"
strSQL = strSQL & ",TaskOutlineLevel,
TaskStart,TaskOutlineLevel ,TaskOutlineLevel,TaskOutlineLevel,TaskDuration
FROM Tasks where TaskOutlineNumber <> '0'"
Set cnsubplan = cnplan(prjname)
Set rsTasks = CreateObject("adodb.recordset")
Call rsTasks.Open(strSQL, cnsubplan)
'Process recordset
rsTasks.Close
cnsubplan.Close
Set rsTasks = Nothing
Set cnsubplan = Nothing
End Sub
==========================================================
Public Function cnplan(strPlanname As String) As Object
'Sets up a connection to a plan
strConn = "Provider=Microsoft.Project.OLEDB." & strVersion & ";PROJECT
NAME=" & strPlanname
Set cnplan = CreateObject("adodb.connection")
cnplan.Open (strConn)
End Function
==========================================================