Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro to dinamicaly define the search string

I want to do this: A user type in a field value to search in an input box and a macro defines what needs to be searched.

In example: the user types in C and 3 searches will be defined:

C,

*,C*

*C,*

I want to do this because when the user searches for C I don't want to include VC CS, etc, I just want C and C in a comma separated list.

The data source is a mess so sometimes a value is correct but someothers a row groups different values in a list (comma separated).

Can you guys help me?

1 Solution

Accepted Solutions
johnw
Champion III
Champion III


Igor Alcantara wrote:Another question regarding to this: how can I apply more than 1 search at the same time?


That part I can answer. Look for "advanced search" in the help. In this case, you could use this:

=wildmatch(MyField,'C,','*,C*','*C,*')

Not sure about the macro itself, though.

View solution in original post

12 Replies
Not applicable
Author

Another question regarding to this: how can I apply more than 1 search at the same time?

johnw
Champion III
Champion III


Igor Alcantara wrote:Another question regarding to this: how can I apply more than 1 search at the same time?


That part I can answer. Look for "advanced search" in the help. In this case, you could use this:

=wildmatch(MyField,'C,','*,C*','*C,*')

Not sure about the macro itself, though.

Not applicable
Author

Can I use that in the Search Object also?

johnw
Champion III
Champion III


Igor Alcantara wrote:Can I use that in the Search Object also?


Looks like the answer is "no" - you can't combine Advanced Search with a Search Object. Unfortunate. I can see how it wouldn't work for something like the expression I gave, since it explicitly lists a field name, though even then, why not at least return matches in that field? But I also tried something without a field name, like sum("Hours")>100. It works just fine in a normal search, but returns no results in a search object.

Not applicable
Author

Ok, I'll try that. Thanks.

Not applicable
Author

Is it possible to loop a Selection List and possibibly change the selected values?

johnw
Champion III
Champion III

I suppose you could with a macro.

Edit: ...which isn't a very useful answer. You'll need to look at the API guide, but here are some possibly-useful tidbits:

ActiveDocument.Fields("MyField").getSelectedValues
ActiveDocument.Fields("MyField").getSelectedValues.Count
ActiveDocument.Fields("MyField").getDeselectedValues
ActiveDocument.Fields("MyField").ToggleSelect "Some Value"

Not applicable
Author

One more question: Can I create a Bookmark in a macro? If so, what is the code I can use for that?

Not applicable
Author

Also, getSelectedValues and getDeselectedValues return both zero if I have no value selected. I need to know and loop through all possible values in a field. Any other guess?