We help IT Professionals succeed at work.
Get Started

How use code just one time

SteveL13
SteveL13 asked
on
114 Views
Last Modified: 2020-02-04
I have the following code in several onclick events on a form.  But it seems redundant to keep repeating the code for each onclick event.  How can I use this code just one time and call it from each onclick event?

    If Nz(Me.txtPreferredName, "") = "" Then
        MsgBox "Enter selection in 1stField!!!"
        Me.txt1stField.SetFocus
        Exit Sub
    Else
        If Nz(Me.cboCampus, "") = "" Then
            MsgBox "Enter selection in 2ndField!!!"
            Me.cbo2ndField.SetFocus
            Exit Sub
        Else
            If Nz(Me.txtLastName, "") = "" Then
                MsgBox "Enter selection in 3rdField!!!"
                Me.txt3rdField.SetFocus
                Exit Sub
            Else
                If Nz(Me.txtFirstName, "") = "" Then
                    MsgBox "Enter selection in 4thField!!!"
                    Me.txt4thField.SetFocus
                    Exit Sub
                Else
                    If Nz(Me.cboClass, "") = "" Then
                        MsgBox "Enter selection in 5thField!!!"
                        Me.cbo5thField.SetFocus
                        Exit Sub
                    Else
                        If Nz(Me.txtPhone1, "") = "" Then
                            MsgBox "Enter selection in 6thField!!!"
                            Me.txt6thField.SetFocus
                            Exit Sub
                        Else
                            If Nz(Me.cboCycle, "") = "" Then
                                MsgBox "Enter selection in 7thField!!!"
                                Me.cbo7thField.SetFocus
                                Exit Sub
                            Else
                                If Nz(Me.txtEmailAddress1, "") = "" Then
                                    MsgBox "Enter selection in 8thField!!!"
                                    Me.txt8thField.SetFocus
                                    Exit Sub
                                Else
                                    If Nz(Me.txtTraining_Start_Date, "") = "" Then
                                        MsgBox "Enter selection in 9thField!!!"
                                        Me.txt9thField.SetFocus
                                        Exit Sub
                                    Else
                                        If Nz(Me.txtTraining_End_Date, "") = "" Then
                                            MsgBox "Enter selection in 10thField!!!"
                                            Me.txt10thField.SetFocus
                                            Exit Sub
                                        Else
                                            If Nz(Me.txtMember_End_Date_Term_Of_Service, "") = "" Then
                                                MsgBox "Enter selection in 11thField!!!"
                                                Me.txt11thField.SetFocus
                                                Exit Sub
                                            Else
                                                If Nz(Me.cboNCCC_status, "") = "" Then
                                                    MsgBox "Enter selection in 12thField!!!"
                                                    Me.cbo12thField.SetFocus
                                                    Exit Sub
                                                Else
                                                    If Nz(Me.cboProgram, "") = "" Then
                                                        MsgBox "Enter selection in 13thField!!!"
                                                        Me.cbo13thField.SetFocus
                                                        Exit Sub
                                                    Else
                                                        If Nz(Me.cboGroup, "") = "" Then
                                                            MsgBox "Enter selection in 14thField!!!"
                                                            Me.cbo14thField.SetFocus
                                                            Exit Sub
                                                        Else
                                                            If Nz(Me.txtNSA_ID, "") = "" Then
                                                                MsgBox "Enter selection in 15Field!!!"
                                                                Me.txt15Field.SetFocus
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If
Comment
Watch Question
IT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 20 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE