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

Checking return for Select in macro

I want to provide a message if the Select in the macro fails. With the code below, I'm getting the error Expected 'Then', with "District of Columbia" = false then highlighted. Anyone have a suggestion? Thanks.

if ActiveDocument.Fields("STATE_NAME"). Select "District of Columbia" = false then msgbox("Data does not exist for the selected Reporting State.")

end if





1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

To get a return value from Select, you must use the function argument form -- that is, enclose the argument in parens.

if ActiveDocument.Fields("STATE_NAME").Select("District of Columbia") = false then msgbox("Data does not exist for the selected Reporting State.")


Also. if using the single-line syntax If, don't include an End If.

-Rob

View solution in original post

3 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

To get a return value from Select, you must use the function argument form -- that is, enclose the argument in parens.

if ActiveDocument.Fields("STATE_NAME").Select("District of Columbia") = false then msgbox("Data does not exist for the selected Reporting State.")


Also. if using the single-line syntax If, don't include an End If.

-Rob

Not applicable
Author

Sorry, that shouldn't have posted.





Not applicable
Author

Rob, that is exactly what I needed. Thanks for your help. Laurie