Hi
I am after a way to handle an error occuring inside an error handler
My code is as follows
Private Sub CommandButton3_Click()
Dim E_name As String
Dim Denominator As Integer
Dim Customer_No As Integer
Dim Job_No As String
Err = True
Sheets("Jobs").Range("AD1").Value = Job_No_TB
On Error GoTo MyErrorHandler:
E_name = Application.WorksheetFunction.VLookup(Job_No_TB.Value, Sheet11.Range("AD3:AN3"), 11, False)
MsgBox (E_name)
'Set jobs for customer to be displayed
Me.ListBox1.RowSource = "Job"
'Fill out user form with customer details
If Len(E_name) > 0 Then
Q_Business_Name_TB.Value = Application.WorksheetFunction.VLookup(E_name, Sheet3.Range("B3:I1000"), 2, False)
Q_Phone_TB.Value = Application.WorksheetFunction.VLookup(E_name, Sheet3.Range("B3:I1000"), 3, False)
Q_Email_TB.Value = Application.WorksheetFunction.VLookup(E_name, Sheet3.Range("B3:I1000"), 4, False)
Q_Address_TB.Value = Application.WorksheetFunction.VLookup(E_name, Sheet3.Range("B3:I1000"), 5, False)
Q_City_TB.Value = Application.WorksheetFunction.VLookup(E_name, Sheet3.Range("B3:I1000"), 6, False)
Q_State_TB.Value = Application.WorksheetFunction.VLookup(E_name, Sheet3.Range("B3:I1000"), 7, False)
Q_Post_Code_TB.Value = Application.WorksheetFunction.VLookup(E_name, Sheet3.Range("B3:I1000"), 8, False)
End If
Exit Sub
MyErrorHandler:
Job_No = "Job-" & Job_No_TB.Value
Sheets("Jobs").Range("AD1").Value = Job_No
On Error GoTo Errormask:
'Second error handling here
E_name = Application.WorksheetFunction.VLookup(Job_No, Sheet11.Range("AD3:AN3"), 11, False)
Resume Next
Errormask:
MsgBox ("Job not present, Please start new job first")
End Sub
If an error occurs at
'Second error handling here
E_name = Application.WorksheetFunction.VLookup(Job_No, Sheet11.Range("AD3:AN3"), 11, False)
This means that the job number is still not valid even after it has tried to be corrected.
I would like the
MsgBox ("Job not present, Please start new job first")
to show.
Any ideas???
Cheers
Grant Astley
Bookmarks