
Using MS Access to populate specific fields in MS Project
I created a command button on one of my MS Access application pages using a
module containing the code below. I can now open MS Project with no
problem. But as soon as I add, or remove the comments " ' " from, the lines
of code, i.e., "objProject.SetTaskField "Name", dynTasks!Tasks,
intCurrTask", I get the following error message when I click on the command
button:
Run-time error '1101':
The argument value is not valid.
Check that the value is correct and that it is the correct type for the
argument.
When I select the "Debug" option, my code appears with the first "objProject
SetTask Field . . ." that it comes across that creates the bug.
Let me add, I have made certain that I correctly used the field names in
both MS Project and my MS Access application. The same problem occurs on
two separate MS Access 98 and MS Access 2000 machines.
Here is the full description of the code use in the module:
Option Compare Database
Function AccessToProjectAutomation()
Dim dblocal As Database
Dim dynTasks As Recordset
Dim intCurrTask As Integer
'On Error GoTo Error_OLEAccessToProject
Set dblocal = CurrentDb()
Set dynTasks = dblocal.OpenRecordset("Tasks", dbOpenDynaset)
'--Create an instance of Project
Set objProject = CreateObject(Class:="MSProject.Application")
With objProject
.DisplayAlerts = False
.FileNew
End With
'--Initialize the counter for the Unique Task ID
intCurrTask = 0
Do Until dynTasks.EOF
'--Increment the counter for the Task ID
intCurrTask = intCurrTask + 1
'--Use the SetTaskField method to
'--Write data from Access record to Project
objProject.SetTaskField "Name", dynTasks!Tasks, intCurrTask
objProject.SetTaskField "Start", dynTasks!start, intCurrTask
objProject.SetTaskField "Duration", dynTasks!Duration, intCurrTask
objProject.SetTaskField "Predecessors", dynTasks!Predecessors, intCurrTask
objProject.SetTaskField "Resource Names", dynTasks!Resources, intCurrTask
dynTasks.MoveNext
Loop
'--Make project visible
With objProject
.Visible = True
.AppMaximize
End With
Exit Function
Error_OLEAccessToProject:
Beep
MsgBox "The following OLE Error has occurred:" & vbCrLf & Err.description,
vbCritical, "Ole Error!"
Exit Function
End Function