VBA type mismatch on GetField Method

T

Thomas V

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
 
T

Thomas V

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
 
J

Jack Dahlgren

You are welcome.

-Jack


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
 

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