Dialog Box insert values on Custom Properties.

  • Thread starter Joao Bras - Brasmatica
  • Start date
J

Joao Bras - Brasmatica

I have a template, now I want to make some code to make a dialog box to
appear and ask some values. Then put this values on Custom Properties for
that file.

The Custom Properties are: Client, Reference and Number. If possible also
one other Custom Property Field that I created named OT.

I can't write the Values, anyone can help me on that?

Thanks.
 
J

John

Joao,
There are various ways to have code ask the user for input. The simplest
is probably with an InputBox Function (get all values at once) or a
series of InputBox Functions (get each value one at a time). A more
elegant approach is through a userform. I'll keep the code simple and
use multiple InputBox statements. Note: this code assumes all input
values are text except for the Reference, which is a number. Change the
type values as appropriate for your need. Note also that a reference (VB
Editor/Tools/References) to the Office object library needs to be set or
an error will occur. In my case, that is "Microsoft Office 11.0 Object
Library" for Office 2000.

Sub CustProp()
Guy = InputBox("Enter a client name", "Custom Properties Input #1")
Ref = InputBox("Enter a reference", "Custom Properties Input #2")
Num = InputBox("Enter a number", "Custom Properties Input #3")
OTFld = InputBox("Enter an OT value", "Cutom Properties Input #4")

With ActiveProject.CustomDocumentProperties
.Add Name:="Client", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:=Guy
.Add Name:="Reference", _
LinkToContent:=False, _
Type:=msoPropertyTypeNumber, _
Value:=Ref
.Add Name:="Number", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:=Num
.Add Name:="OT", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:=OTFld
End With

End Sub

Hope this helps.
John
 
J

Joao Bras - Brasmatica

Thanks it worked. I've created a user form and adapted the code. Now when it
opens the project it opens a form, the user enter the data and save. The
form closes, and voilá! :) It works fine.

One thing that happens is that if the propertie already exists it gives a
error, but I'll get over it.

Now do you know if I can use this values in the header of a report or a view
print? I tried &[Client] for example, and it doesn't work...

Thanks once more, Great help indeed ;)
 
J

John

Jaoa,
Good, I'm glad it worked for you. While I was developing the code and
testing it, I also tried to find out how an existing value could be
changed but didn't find anything. I'm sure there is a method for
deleting a custom property (other than manually) but if there is, the
method is well hidden in the help file.

As far as using the custom values in a header, I don't know. Like you I
would have to play with it until I found a solution. Hopefully someone
else can field this question.

John
 
J

John

Joao,
Now that I've had a little time to think about it (getting a custom
properties value into the header), here is what I suggest. In the same
macro that sets the custom values, also put the values into spare text
fields for the Project Summary Task. The spare text field can then be
added to the header in the Page Setup window.

John
 
J

Joao Bras - Brasmatica

Thanks John,

I've thinked about that, but I can't write values on that fields. It says
it's a constant.
Well I'm a wanna-be-newbie ;) in VBA, so maybe I'm doing something wrong,
but I'll continue to try...
This way I'm learning a few things.

Thanks, once more.
 
J

John

Joao,
It sounds like you are trying to write the "type" to the field. The type
is a constant. In VBA anything that starts with "pj" or "mso" (and
probably a few others) is a constant. However, the "Value" itself is not
a constant, it is either text, a date, number or boolean (yes or no). In
the case of the macro I included earlier in the thread, you should be
trying to write "guy", "ref", "num" and "OTFld" to each of 4 spare text
fields at the Project Summary level. For example, insert the following
line either before or after the With-End With loop in the previous code:
ActiveProject.ProjectSummaryTask.Text1 = Guy

Repeat the above line of code for each of the four values.

Hope this helps.
John
 
J

Joao Bras - Brasmatica

Hi John,

It worked. Many Thanks!!!

I've tried MSProject.PjField.pjResourceText1 = Cliente
Now that you have explained I understood what I've done wrong.

Thanks for everything.

Hope to be of some assistance as you've been to me.

Forgive my poor english

Joao
 
J

John

Joao,
You're welcome. As you get more experienced with Project and VBA perhaps
you can contribute your knowledge by answering posts.

John
 

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