I am fairly new to VBA and would like to know if the following code could be simplified using arrays.
The code fires on the click action of a SAVE command button. It is checking that all fields have been completed.
Any help would be appreciated.
Private Sub cmdSaveExit_Click()
'Declare variables
Dim first 'First Name
Dim last 'Last Name
Dim dept 'Department
Dim cont 'Contract
Dim start 'Start Date
Dim leave 'Leave Date
'Set Variables
With Me
first = .First_Name
last = .Last_Name
dept = .Department
cont = .Shift_Worker
start = .Date_Joined_Company
leave = .Date_Left_Company
End With
'Check required variables are filled in
If IsNull(first) Then
MsgBox ("First Name must be supplied"), _ vbExclamation, "Error!"
Me.First_Name.SetFocus
GoTo exitSub
End If
If IsNull(last) Then
MsgBox ("Last Name must be supplied"), _ vbExclamation, "Error!"
Me.Last_Name.SetFocus
GoTo exitSub
End If
If IsNull(dept) Then
etc...........
exitSub:
Exit Sub
End Sub
The code fires on the click action of a SAVE command button. It is checking that all fields have been completed.
Any help would be appreciated.
Private Sub cmdSaveExit_Click()
'Declare variables
Dim first 'First Name
Dim last 'Last Name
Dim dept 'Department
Dim cont 'Contract
Dim start 'Start Date
Dim leave 'Leave Date
'Set Variables
With Me
first = .First_Name
last = .Last_Name
dept = .Department
cont = .Shift_Worker
start = .Date_Joined_Company
leave = .Date_Left_Company
End With
'Check required variables are filled in
If IsNull(first) Then
MsgBox ("First Name must be supplied"), _ vbExclamation, "Error!"
Me.First_Name.SetFocus
GoTo exitSub
End If
If IsNull(last) Then
MsgBox ("Last Name must be supplied"), _ vbExclamation, "Error!"
Me.Last_Name.SetFocus
GoTo exitSub
End If
If IsNull(dept) Then
etc...........
exitSub:
Exit Sub
End Sub