Hi.

I've run into a VBA issue I can't seem to resolve.

I'm trying to use the 'GetField' method against a resource object but
for various reasons I can't provide the FieldID as a pjField type
variable. I do however have a string variable (strPjFieldName) which
has the FieldID name I need.

Is there a way to typecast from a String variable to a pjField
variable?

Here's some example code

Sub MySub()
Dim rs As Resources
Dim r As Resource
Dim strPjFieldName As String
Dim strMsg As String

strPjFieldName = "pjResourceBookingType"

Set rs = ActiveProject.Resources
For Each r In rs
If Not r Is Nothing Then
strMsg = strMsg & r.GetField(FieldID:=strPjFieldName) &
vbCr
End If
Next r
MsgBox strMsg
End Sub

What I would like is for this procedure to return the values of
"r.BookingType".

How does the example apply to a real scenario? Imagine you have a form
with 70 fields. Each of those representing a different field from the
resource object. I do not want to code the link between each form
field and its respective data field in the resource object
individually. Rather, I'd like to loop through all the fields on the
form, derive the resource field I need to source the data from, and
then get the data so I can display it on the form.

Thanks for your help.

Thomas Vanparys

Re: VBA type mismatch on GetField Method by Jack

Jack
Fri Apr 18 11:30:29 CDT 2008

Try the FieldNameToFieldConstant method.

-Jack Dahlgren


"Thomas V" <thomas.vanparys@gmail.com> wrote in message
news:2a5f8b3b-9d72-4db8-b78e-2da23da29fd8@d1g2000hsg.googlegroups.com...
> Hi.
>
> I've run into a VBA issue I can't seem to resolve.
>
> I'm trying to use the 'GetField' method against a resource object but
> for various reasons I can't provide the FieldID as a pjField type
> variable. I do however have a string variable (strPjFieldName) which
> has the FieldID name I need.
>
> Is there a way to typecast from a String variable to a pjField
> variable?
>
> Here's some example code
>
> Sub MySub()
> Dim rs As Resources
> Dim r As Resource
> Dim strPjFieldName As String
> Dim strMsg As String
>
> strPjFieldName = "pjResourceBookingType"
>
> Set rs = ActiveProject.Resources
> For Each r In rs
> If Not r Is Nothing Then
> strMsg = strMsg & r.GetField(FieldID:=strPjFieldName) &
> vbCr
> End If
> Next r
> MsgBox strMsg
> End Sub
>
> What I would like is for this procedure to return the values of
> "r.BookingType".
>
> How does the example apply to a real scenario? Imagine you have a form
> with 70 fields. Each of those representing a different field from the
> resource object. I do not want to code the link between each form
> field and its respective data field in the resource object
> individually. Rather, I'd like to loop through all the fields on the
> form, derive the resource field I need to source the data from, and
> then get the data so I can display it on the form.
>
> Thanks for your help.
>
> Thomas Vanparys



Re: VBA type mismatch on GetField Method by Thomas

Thomas
Fri Apr 18 13:15:33 CDT 2008

Thanks Jack!

That did the trick.

Btw what I'm working was inspired from an article you wrote titled:
Analyze Microsoft Project Resource Usage Data In Excel
I thank you for that too :-)

All the best,
Thomas Vanparys

On Apr 18, 6:30=A0pm, "Jack Dahlgren" <j...@zo-d.com> wrote:
> Try the FieldNameToFieldConstant method.
>
> -Jack Dahlgren
>
> "Thomas V" <thomas.vanpa...@gmail.com> wrote in message
>
> news:2a5f8b3b-9d72-4db8-b78e-2da23da29fd8@d1g2000hsg.googlegroups.com...
>
>
>
> > Hi.
>
> > I've run into a VBA issue I can't seem to resolve.
>
> > I'm trying to use the 'GetField' method against a resource object but
> > for various reasons I can't provide the FieldID as a pjField type
> > variable. I do however have a string variable (strPjFieldName) which
> > has the FieldID name I need.
>
> > Is there a way to typecast from a String variable to a pjField
> > variable?
>
> > Here's some example code
>
> > Sub MySub()
> > =A0 =A0Dim rs As Resources
> > =A0 =A0Dim r As Resource
> > =A0 =A0Dim strPjFieldName As String
> > =A0 =A0Dim strMsg As String
>
> > =A0 =A0strPjFieldName =3D "pjResourceBookingType"
>
> > =A0 =A0Set rs =3D ActiveProject.Resources
> > =A0 =A0For Each r In rs
> > =A0 =A0 =A0 =A0If Not r Is Nothing Then
> > =A0 =A0 =A0 =A0 =A0 =A0strMsg =3D strMsg & r.GetField(FieldID:=3DstrPjFi=
eldName) &
> > vbCr
> > =A0 =A0 =A0 =A0End If
> > =A0 =A0Next r
> > =A0 =A0MsgBox strMsg
> > End Sub
>
> > What I would like is for this procedure to return the values of
> > "r.BookingType".
>
> > How does the example apply to a real scenario? Imagine you have a form
> > with 70 fields. Each of those representing a different field from the
> > resource object. I do not want to code the link between each form
> > field and its respective data field in the resource object
> > individually. Rather, I'd like to loop through all the fields on the
> > form, derive the resource field I need to source the data from, and
> > then get the data so I can display it on the form.
>
> > Thanks for your help.
>
> > Thomas Vanparys- Hide quoted text -
>
> - Show quoted text -

Re: VBA type mismatch on GetField Method by Jack

Jack
Fri Apr 18 14:18:58 CDT 2008

You are welcome.

-Jack


"Thomas V" <thomas.vanparys@gmail.com> wrote in message
news:a84016cf-9dcb-4751-94a4-ab3c0e81b500@b64g2000hsa.googlegroups.com...
Thanks Jack!

That did the trick.

Btw what I'm working was inspired from an article you wrote titled:
Analyze Microsoft Project Resource Usage Data In Excel
I thank you for that too :-)

All the best,
Thomas Vanparys

On Apr 18, 6:30 pm, "Jack Dahlgren" <j...@zo-d.com> wrote:
> Try the FieldNameToFieldConstant method.
>
> -Jack Dahlgren
>
> "Thomas V" <thomas.vanpa...@gmail.com> wrote in message
>
> news:2a5f8b3b-9d72-4db8-b78e-2da23da29fd8@d1g2000hsg.googlegroups.com...
>
>
>
> > Hi.
>
> > I've run into a VBA issue I can't seem to resolve.
>
> > I'm trying to use the 'GetField' method against a resource object but
> > for various reasons I can't provide the FieldID as a pjField type
> > variable. I do however have a string variable (strPjFieldName) which
> > has the FieldID name I need.
>
> > Is there a way to typecast from a String variable to a pjField
> > variable?
>
> > Here's some example code
>
> > Sub MySub()
> > Dim rs As Resources
> > Dim r As Resource
> > Dim strPjFieldName As String
> > Dim strMsg As String
>
> > strPjFieldName = "pjResourceBookingType"
>
> > Set rs = ActiveProject.Resources
> > For Each r In rs
> > If Not r Is Nothing Then
> > strMsg = strMsg & r.GetField(FieldID:=strPjFieldName) &
> > vbCr
> > End If
> > Next r
> > MsgBox strMsg
> > End Sub
>
> > What I would like is for this procedure to return the values of
> > "r.BookingType".
>
> > How does the example apply to a real scenario? Imagine you have a form
> > with 70 fields. Each of those representing a different field from the
> > resource object. I do not want to code the link between each form
> > field and its respective data field in the resource object
> > individually. Rather, I'd like to loop through all the fields on the
> > form, derive the resource field I need to source the data from, and
> > then get the data so I can display it on the form.
>
> > Thanks for your help.
>
> > Thomas Vanparys- Hide quoted text -
>
> - Show quoted text -