Validation on InfoPath attachment field

This is not my solution.  100% credit goes to Max Morrow.  I just know I’m going to need this info again and wouldn’t want to lose it should Max take this blog post down. 

Here is his solution for not allowing a user to save an InfoPath form without first including at least one attachment.  I copying this excerpt word for word.  you can read the full post here Validating the Attachments Field

1.) Create a field in addition to the attachments field. In my case, I called the field I created Attachment Validation.

2.) Drop your field onto the form and remove the borders and background. Then set the default text to ‘Attachments:’

InfoPath 2010 Attachments Field Validation

3.) Finally, lets apply some validation to this field. Right click the field on your form and select Rules > Manage Rules.

In my case, I needed to make sure there was at least one attachement. So, I counted the :attachmentURL instances and checked if there were more than 0. To do this, I used a custom expression:

Now with all of that complete you will have a separate field that validates the attachments field and if there are no attachments, the text in the left hand column will be surrounded in the standard red dashed border.

InfoPath 2010 Validation on Attachments Field

NOTE:

To get to the ‘:attachmentsURL’ field you need to create the validation make sure you go into Advanced View of the fields.

InfoPath 2010 Attachments :attachmentURL field advanced view

Thanks for this great solution, Max!