#example - exits procedure if something error description happens
Private Sub btnAddNew_Click()
errorStr = errorCheck 'checks for errors ie. missing gaps in textfields
If Not (errorStr = "") Then 'if something wrong with wat user entered
XML Validation is the process of making sure that XML documents/schemas comply by the rules of the language. This process is similar to compiling of a VBA program. Any good XML editor will display error messages whenever XML language rules are not followed.
Although programs like Notepad can be used to create XML documents, these editors do not have validation features available.
Insert this code into userform code just like you would any procedure:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode=0 Then
MsgBox “Please use the exit button instead”, vbCritical
On Error GoTo <Error handler name>
‘normal code here
<Error handler name>:
This entire block of code above is meant to go into a single procedure.
On Error GoTo ErrorHandler 'Begins the error handling routine
z = 10 / 0 'Divide by ZERO Error Raises
Exit Sub 'exit so does not continue onto the errorhandler again
ErrorHandler: ' Error-handling routine
If Err.Number <> 0 Then '0 means no error
MsgBox "Error #" & Err.Number & " : " & Chr(10) & Err.Description 'displays the error
Resume Next 'goes to whatever code is after where the error line was