Hi Sam and welcome,
What you basically have to do is make a Conditional Formatting rule that counts the number of rows in your retrieved datasource. If the rows are more than 0 (zero) then you hide the error message. I have implemented your requirement in the IP form and reattached it with my post.
There are a couple of things I changed.
First of all, it's better to put your message in an expression box control this will allow the text to be rendered as plain text instead of having borders around it.
Next, you need to add a conditional formatting rule in order to show and hide the message. You can achieve this by following these steps:
1- Right click on the expression box and go to Conditional Formating...
2- On the Conditional Formatting dialog box, click on Add...
3- On the Conditional Format dialog box, under "If this condition is true:", in the fields dropdownlist select "Select a field or group...".
4- In the Select a Field or Group dialog box, navigate to your secondary datasource. In our case it's "InfoPathTestData (Secondary)".
5- In the Select a Field or Group dialog box, navigate in the datasource tree and select one of the dataFields for example ":Title"
6- In the Select a Field or Group dialog box, under the Select dropdownlist, select "Number of occurrences of Title" and press OK
7- On the Conditional Format dialog box, under "If this condition is true:", in the criteria dropdownfield select "is greater than"
8- On the Conditional Format dialog box, under "If this condition is true:", in the value dropdownfield select "type a number..." and type 0 (zero).
9- On the Conditional Format dialog box, under "Then apply this formatting:", check the "Hide this control" checkbox.
10- Press OK on all dialog boxes
11- Test your form
Regards,