Hi,
I have a user form with some fields for user input. If any of the fields are empty or not long enough I want to return all errors in one list. I am doing that by checking the fields value and if it's empty/too short add a string to an array.
Then I am joining the array with CRLF and using the joined string for the Description parameter in Err.Raise and in my error handler updating a label with the error description. This works, but I'm unsure what to do with the Err.Number value.
Dim Results(), Result As String
Dim ErrorNum, i As Long
ErrorNum = 0
ReDim Preserve Results(0)
If IRN = "" Or GetCaseRef(IRN) = "" Then
Result = "You have entered an incorrect value for case reference"
If IRN = "" Then
ErrorNum = 1001
Result = Result & " [cannot be blank]"
Else
ErrorNum = 1002
Result = Result & " [invalid format]"
End If
Results(UBound(Results)) = Result
ReDim Preserve Results(UBound(Results) + 1)
End If
If Description = "" Or (Len(Description) > 0 And Len(Description) < 10) Then
Result = "You have entered an incorrect value for e-mail description/narrative"
If Description = "" Then
ErrorNum = 1011
Result = Result & " [cannot be blank]"
ElseIf Len(Description) > 0 And Len(Description) < 10 Then
ErrorNum = 1012
Result = Result & " [minimum length 10 characters]"
End If
Results(UBound(Results)) = Result
ReDim Preserve Results(UBound(Results) + 1)
End If
If SaveToFolder_Form.Attach_CheckBox.value = True And (AttachFolder = "" Or (Len(AttachFolder) > 0 And Len(AttachFolder) < 10)) Then
Result = "You have entered an incorrect value for attachments folder name"
If AttachFolder = "" Then
ErrorNum = 1021
Result = Result & " [cannot be blank]"
ElseIf Len(AttachFolder) > 0 And Len(AttachFolder) < 10 Then
ErrorNum = 1022
Result = Result & " [minimum length 10 characters]"
End If
Results(UBound(Results)) = Result
ReDim Preserve Results(UBound(Results) + 1)
End If
If Item.Sent = False Then
ErrorNum = 1031
Result = "This message is being edited. Send or save it and try again"
Results(UBound(Results)) = Result
ReDim Preserve Results(UBound(Results) + 1)
End If
Result = Join(Results, vbCrLf)
Erase Results
If ErrorNum <> 0 Then Err.Raise Number:=vbObjectError + -1, Description:=Result
There must be a better way of doing this? I don't want to return just the 'current' error field each time one is wrong.
Thanks