Settings BokkingType for resources using VBA

S

Silvia Rivero

I have a question...

Is possible set bookingtype to proposed for a resource in a project using
VBA in the Macro?

We need assures that the initial equipment of the project has only proposed
resources

In the macro we have this statement ...
For Each oResource In oTask.Resources
oResource.BookingType = pjBookingTypeProposed
Next

But this (oResource.BookingType = pjBookingTypeProposed ) gives a message of
run-time error 1004

Any idea?

Thanks,
Silvia R.
 
J

John

Silvia Rivero said:
I have a question...

Is possible set bookingtype to proposed for a resource in a project using
VBA in the Macro?

We need assures that the initial equipment of the project has only proposed
resources

In the macro we have this statement ...
For Each oResource In oTask.Resources
oResource.BookingType = pjBookingTypeProposed
Next

But this (oResource.BookingType = pjBookingTypeProposed ) gives a message of
run-time error 1004

Any idea?

Thanks,
Silvia R.

Silvia,
Yes it is possible to set the bookingtype using VBA. There is nothing
inherently wrong with the code snippet you show as long as the object
"oTask" is defined. How does your code define the oTask object?

We need more information in order to help you.

John
Project MVP
 
S

Silvia Rivero

Hi Jonh,

Thank you for your help.
Here is the function write for us... some message are in spanish, sorry!
Riun-time error 1004 ocurr in line:
"oResource.BookingType = pjBookingTypeProposed "

Sub CheckResources()
Dim oResource As Resource
Dim msg As String
Dim msgcont As Integer
Dim msgcont1 As Integer
Dim bResultado As Boolean
Dim oTask As Task

Dim PCF11 As String
Dim POU3 As String
Dim AñoPortafolio As Integer
Dim NoPortafolio As Byte
AñoPortafolio = 0
NoPortafolio = 0

With ActiveProject.ProjectSummaryTask
POU3 = .EnterpriseProjectOutlineCode3
PCF11 = .EnterpriseProjectText11
End With
If Len(POU3) > 0 Then
AñoPortafolio = CInt(Right(POU3, 4))
NoPortafolio = CByte(InStr(POU3, "No Portafolio"))
End If
msgcont = 0
If PCF11 = "En Espera" And AñoPortafolio > 2004 And NoPortafolio = 0 Then
For Each oTask In ActiveProject.Tasks
If Not oTask Is Nothing Then
If oTask.Resources.Count <> 0 Then
For Each oResource In oTask.Resources
If (oResource.BookingType = pjBookingTypeCommitted And
oResource.Enterprise = "Verdadero" And oResource.EnterpriseRBS <> "") Then
If msgcont = 0 Then
msg = "Recuerde por favor construir el Equipo de
Proyecto con recursos tipo de reserva Propuestas."
msg = msg & Chr(13) & "Los recursos de tipo de
reserva Confirmado serán eliminados de proyecto."
MsgBox msg, vbExclamation
msgcont = 1
End If
oResource.BookingType = pjBookingTypeProposed
End If
Next
End If
End If
Next
End If
End Sub


Thanks,
Silvia Rivero.


"John" escribió:
 
J

John

Silvia Rivero said:
Hi Jonh,

Thank you for your help.
Here is the function write for us... some message are in spanish, sorry!
Riun-time error 1004 ocurr in line:
"oResource.BookingType = pjBookingTypeProposed "

Sub CheckResources()
Dim oResource As Resource
Dim msg As String
Dim msgcont As Integer
Dim msgcont1 As Integer
Dim bResultado As Boolean
Dim oTask As Task

Dim PCF11 As String
Dim POU3 As String
Dim AñoPortafolio As Integer
Dim NoPortafolio As Byte
AñoPortafolio = 0
NoPortafolio = 0

With ActiveProject.ProjectSummaryTask
POU3 = .EnterpriseProjectOutlineCode3
PCF11 = .EnterpriseProjectText11
End With
If Len(POU3) > 0 Then
AñoPortafolio = CInt(Right(POU3, 4))
NoPortafolio = CByte(InStr(POU3, "No Portafolio"))
End If
msgcont = 0
If PCF11 = "En Espera" And AñoPortafolio > 2004 And NoPortafolio = 0 Then
For Each oTask In ActiveProject.Tasks
If Not oTask Is Nothing Then
If oTask.Resources.Count <> 0 Then
For Each oResource In oTask.Resources
If (oResource.BookingType = pjBookingTypeCommitted And
oResource.Enterprise = "Verdadero" And oResource.EnterpriseRBS <> "") Then
If msgcont = 0 Then
msg = "Recuerde por favor construir el Equipo de
Proyecto con recursos tipo de reserva Propuestas."
msg = msg & Chr(13) & "Los recursos de tipo de
reserva Confirmado serán eliminados de proyecto."
MsgBox msg, vbExclamation
msgcont = 1
End If
oResource.BookingType = pjBookingTypeProposed
End If
Next
End If
End If
Next
End If
End Sub


Thanks,
Silvia Rivero.

Silvia,
Again I don't see anything obviously wrong with your code and just to
check, I copied it to my VBA editor and ran it against one of my test
files. I commented out the first "If" statement (i.e. "If PCF11...")
since I don't have any enterprise values set. I also commented out the
first "If" statement after the "For Each oResource..." so I could
guarantee execution of the statement where your run time error occurred.
However, when I made those changes and ran the code, it ran ok with no
error messages. You might want to try commenting out the same statements
I did and see if you still get an error.

Just a side comment, the "If oTask.Resources.Count <> 0 Then" statement
(and its associated "End If") are redundant. The following "For Each..."
will automatically skip any tasks without resources.

Hope this helps.
John
Project MVP
 
S

Silvia Rivero

Hi John,

I commented out the statement that you refer, but the run-time error 1004
persist.
This solution is in Project Professional connected to Project Server

I also did a test to setting BookinType using PDS, and also display an
error. In this case the code status error is 64.

Can be something wrong with permissions? I am administrator

Thanks,
Silvia Rivero.

"John" escribió:
 
J

John

Silvia Rivero said:
Hi John,

I commented out the statement that you refer, but the run-time error 1004
persist.
This solution is in Project Professional connected to Project Server

I also did a test to setting BookinType using PDS, and also display an
error. In this case the code status error is 64.

Can be something wrong with permissions? I am administrator

Thanks,
Silvia Rivero.

Silvia,
Unfortunately I don't use Project Server so there's not a whole lot more
I can suggest. Since the basic code does work without server (i.e. on my
installation), my guess is that something is wrong with the Server
setup. You might want to try posting on the server newsgroup:
microsoft.public.project.server

Good luck.
John
Project MVP
 
S

Silvia Rivero

John,

Thanks for your help, but I initially post my question in that forum, but
Dale Howard recommended to me there that rather I used this forum

And now? :-(

Silvia Rivero

"John" escribió:
 
J

John

Silvia Rivero said:
John,

Thanks for your help, but I initially post my question in that forum, but
Dale Howard recommended to me there that rather I used this forum

And now? :-(

Silvia Rivero

Silvia,
OK, let's try the following simple code:

Sub Check_R_X()
Dim t As Object, r As Object
For Each t In ActiveProject.Tasks
If Not t Is Nothing Then
For Each r In t.Resources
r.BookingType = pjBookingTypeCommitted
r.BookingType = pjBookingTypeProposed
Next r
End If
Next t
End Sub

Run it and tell me what happens. If you get an error, tell me everything
the error message says.

John
 
S

Silvia Rivero

Hi John,

I test with your sample code, but error persists :-(

The message in spanish is :
Se ha producido el error '1004' en tiempo de ejecución: Error inesperado en
el método.
Using translation, the message is something like:
Error ' 1004 ' in run time has taken place: Unexpected error in the method.

If I press "Finish", display another message like:
Error ' - 2147467259 (80004005) ' in run time has taken place: [
Microsoft][Administrador of controller ODBC] is not the name of the data
source and any predetermined controller did not specify itself.

Thank you for your help.

Silvia Rivero.

"John" escribió:
 
J

John

Silvia Rivero said:
Hi John,

I test with your sample code, but error persists :-(

The message in spanish is :
Se ha producido el error '1004' en tiempo de ejecución: Error inesperado en
el método.
Using translation, the message is something like:
Error ' 1004 ' in run time has taken place: Unexpected error in the method.

If I press "Finish", display another message like:
Error ' - 2147467259 (80004005) ' in run time has taken place: [
Microsoft][Administrador of controller ODBC] is not the name of the data
source and any predetermined controller did not specify itself.

Thank you for your help.

Silvia Rivero.

Silvia,
The fact the the booking type couldn't be set at all tells me the
problem is with the way Server is configured. In other words it is a
Project Server issue not a VBA issue. I suggest one of two things. Try
posting in the Server newsgroup again and mention that we had this
discussion. If you do not get an answer or you are just referred back to
this newsgroup, post a new message in this group. I will not answer it
so hopefully one of my fellow MVPs who knows both Server and VBA will
jump in.

Sorry I couldn't be of more assistance.

John
Project MVP
 
S

Silvia Rivero

Ok John,

I will try in the other forum

Thank you for your help!

Silvia Rivero.

John said:
Silvia Rivero said:
Hi John,

I test with your sample code, but error persists :-(

The message in spanish is :
Se ha producido el error '1004' en tiempo de ejecución: Error inesperado en
el método.
Using translation, the message is something like:
Error ' 1004 ' in run time has taken place: Unexpected error in the method.

If I press "Finish", display another message like:
Error ' - 2147467259 (80004005) ' in run time has taken place: [
Microsoft][Administrador of controller ODBC] is not the name of the data
source and any predetermined controller did not specify itself.

Thank you for your help.

Silvia Rivero.

Silvia,
The fact the the booking type couldn't be set at all tells me the
problem is with the way Server is configured. In other words it is a
Project Server issue not a VBA issue. I suggest one of two things. Try
posting in the Server newsgroup again and mention that we had this
discussion. If you do not get an answer or you are just referred back to
this newsgroup, post a new message in this group. I will not answer it
so hopefully one of my fellow MVPs who knows both Server and VBA will
jump in.

Sorry I couldn't be of more assistance.

John
Project MVP
"John" escribió:
 
S

Silvia Rivero

Hi,

I posted my question on the server newsgroup, but without resutts.
No answer

Help!!!


"John" escribió:
Silvia Rivero said:
Hi John,

I test with your sample code, but error persists :-(

The message in spanish is :
Se ha producido el error '1004' en tiempo de ejecución: Error inesperado en
el método.
Using translation, the message is something like:
Error ' 1004 ' in run time has taken place: Unexpected error in the method.

If I press "Finish", display another message like:
Error ' - 2147467259 (80004005) ' in run time has taken place: [
Microsoft][Administrador of controller ODBC] is not the name of the data
source and any predetermined controller did not specify itself.

Thank you for your help.

Silvia Rivero.

Silvia,
The fact the the booking type couldn't be set at all tells me the
problem is with the way Server is configured. In other words it is a
Project Server issue not a VBA issue. I suggest one of two things. Try
posting in the Server newsgroup again and mention that we had this
discussion. If you do not get an answer or you are just referred back to
this newsgroup, post a new message in this group. I will not answer it
so hopefully one of my fellow MVPs who knows both Server and VBA will
jump in.

Sorry I couldn't be of more assistance.

John
Project MVP
"John" escribió:
 

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