Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I want to write a macro to make default selections based on the values available to users.
For Ex.
There is a field "Prj_Priority" with values 1,2,3,4,5. Different usesr have different values of "Prj_Priority" available to them based on their login, What I want to do in macro is to check for the available values of "Prj_Priority" for a user & then select those values by default while opening the document.
Also, there is one twist here, normally default selections should be 2,3,4 &5 (if all values are available for a user), if only 1,2,3 are available for user then default selection should be 2&3.
I know I need to have a macro/trigger on OnOpen of document. But not very familiar with writing macros.
Any suggestion will be of great help!
Thanks in advance.
EDIT:
I have got the syntax to get the possible values available in the field using the following :
ActiveDocument.Fields("PRJ_Priority").GetPossibleValues
But how to match it with default selections (2,3,4 &5) and then select the same in PRJ_Priority ?
Message was edited by: Shyamal Pandit
Got it! Achieved it using Actions rather than Macro.
For anybody's reference :
I just added 2 actions:
1. Select In field
Field Name : PRJ_Priority
Search String : ='(' & Concat ( DISTINCT [PRJ_Priority], '|') & ')'
2. Toggle Select
Field Name : PRJ_Priority
Search String : ='(*1*)
This helped me in selecting only the values I wanted to select by default.
Thanks everyone for the help!
Hi
If you have a table that links the users to the priority field, then you can use OSUser() or QVUser() to select the user name. The links will resolve the prj_priority fields for you.
In general, I would avoid macros, unless you will never use this model in a server environment. Actions will take care of what you need.
HTH
Jonathan
Hi Jonathan,
Thanks for the reply.
I don't have a table to link priority field to user name. That's the problem.
Actions/Macros anything will do, as of now I am open to all options, just trying to achieve this any how.
You don't need (and should avoid) a macro to do this.
An action of type "Select in field"can handle this
use
="(" & Concat(distinct PRJ_Priority,'|') & ")"
Hi,
Thanks for your reply.
Yes, I am trying to achieve this using "Select in Field" only.
Something like :
=If(GetFieldSelections(Prj_Priority)=1,'',
If(GetFieldSelections(Prj_Priority)=2,2,
If(GetFieldSelections(Prj_Priority)=3,3,
If(GetFieldSelections(Prj_Priority)=4,4,
If(GetFieldSelections(Prj_Priority)=5,5,
)))))
This works perfectly fine, but the problem is, it works only for one value at a time. I have situation where user can have more than one value at a time. I need something similar to what "in" does in SQL.
Hope I made myself clear.
Got it! Achieved it using Actions rather than Macro.
For anybody's reference :
I just added 2 actions:
1. Select In field
Field Name : PRJ_Priority
Search String : ='(' & Concat ( DISTINCT [PRJ_Priority], '|') & ')'
2. Toggle Select
Field Name : PRJ_Priority
Search String : ='(*1*)
This helped me in selecting only the values I wanted to select by default.
Thanks everyone for the help!
="(" & Concat(distinct PRJ_Priority,'|') & ")" will handle multiple selections