@DS2
Instead of trying to validate and throw errors and that sort of thing when a user submits the form, consider not even letting them get to that point.
The process I might take would be as follows:
1) Alter your Invoice DataCard - I'm going to refer to it as Invoice_DataCard1, but substitute whatever yours is. I am also going to refer to the TextInput box in your datacard container as DataCardValue1.
a) Unlock the card
b) Find the ErrorMessage control in your datacard container - I'm going to refer to it as ErrorMessage1
c) Change the Text property of ErrorMessage1 to :
If(
IsBlank(Trim(DataCardValue1.Text)), "An invoice number is required",
CountRows(Filter(yourDataSource, Invoice = Trim(DataCardValue1.Text) ) > 0, "Duplicate invoice not allowed",
"")
d) Change the DelayOutput property of DataCardValue1 to true (to limit the lags when typing)
e) Change the Visible property of ErrorMessage1 to : !IsBlank(ErrorMessage1.Text)
2) Change the DisplayMode property of your Submit Icon to the following:
If(ErrorMessage1.Visible, Disabled, Edit)
Now your users will see when and where there is an issue with the invoice number and will not be allowed to submit the form until it is corrected.
I hope this is clear and helpful for you.