+ Reply to Thread
Results 1 to 3 of 3

Issue with Error Checking

Hybrid View

  1. #1
    Registered User
    Join Date
    06-17-2016
    Location
    Seattle,WA
    MS-Off Ver
    2013
    Posts
    68

    Issue with Error Checking

    So I recently went through and changed some coding around in a form that I made to feed data into a calendar. I added in audienceCombobox and removed all these other checkboxes I had before.

    What is happening now is that with this code below, whenever I fill in all fields and click "Enter Project" nothing happens. But if I take out the first line in
    Sub enterButton
    Which is
      If Not CheckInputs Then Exit Sub 'check for fields to have values
    then the project will be entered fine however I lose my ability to error check and make sure that all fields have a value.

    Any ideas on what could be causing this issue?

    Private Sub enterButton_Click()
    
        If Not CheckInputs Then Exit Sub 'check for fields to have values
        Process GetWs(Me.impactCombobox.Value) ' process data passing the proper worksheet got from GetWs() function
        MsgBox "Project Entered Successfully"
        ClearUFData 'clear the data
    End Sub   
    
    Function CheckInputs() As Boolean
        If Not CheckControl(Me.nameTextbox, "Please enter your Name") Then Exit Function
        If Not CheckControl(Me.projectTextbox, "Please enter a Project Name") Then Exit Function
        If Not CheckControl(Me.initiativeCombobox, "Please select an Initiative") Then Exit Function
        If Not CheckControl(Me.impactCombobox, "Please select an Impact Type") Then Exit Function
        If Not CheckControl(Me.lengthListbox, "") Then If Not CheckControl(Me.lengthListbox2, "Please select Project Length") Then Exit Function
        If Not CheckControl(Me.audienceCombobox, "Please select an Audience") Then Exit Function
        Exit Function
    
        CheckInputs = True
    End Function
    
    Private Function CountSelectedListBoxItems(lb As MSForms.ListBox) As Long
        Dim i As Long
        With lb
            For i = 0 To .ListCount - 1
                If .Selected(i) Then CountSelectedListBoxItems = CountSelectedListBoxItems + 1
            Next i
        End With
    End Function
    
    Function CheckControl(ctrl As MSForms.Control, errMsg As String) As Boolean
        Select Case TypeName(ctrl)
            Case "TextBox"
                CheckControl = Trim(ctrl.Value) <> ""
            Case "ComboBox"
                CheckControl = ctrl.ListIndex <> -1
            Case "ListBox"
                CheckControl = CountSelectedListBoxItems(ctrl) > 0
    '        Case Else
        End Select
        If errMsg = "" Then Exit Function
        If CheckControl Then Exit Function
        ctrl.SetFocus
        MsgBox errMsg
    End Function
    Picture of what my userform looks like is below.
    Attached Images Attached Images

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Issue with Error Checking

    Hi,

    Your function can never return True the way it has been written. You must remove the line highlighted in red below.
    Function CheckInputs() As Boolean
        If Not CheckControl(Me.nameTextbox, "Please enter your Name") Then Exit Function
        If Not CheckControl(Me.projectTextbox, "Please enter a Project Name") Then Exit Function
        If Not CheckControl(Me.initiativeCombobox, "Please select an Initiative") Then Exit Function
        If Not CheckControl(Me.impactCombobox, "Please select an Impact Type") Then Exit Function
        If Not CheckControl(Me.lengthListbox, "") Then If Not CheckControl(Me.lengthListbox2, "Please select Project Length") Then Exit Function
        If Not CheckControl(Me.audienceCombobox, "Please select an Audience") Then Exit Function
        Exit Function
    
        CheckInputs = True
    End Function
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    06-17-2016
    Location
    Seattle,WA
    MS-Off Ver
    2013
    Posts
    68

    Re: Issue with Error Checking

    Thanks, that fixed it... I feel very sad that I didn't manage to catch that haha.

    A case of the Mondays I guess

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Error checking routine - check range values on various worksheets and report if error
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-29-2014, 06:36 AM
  2. Replies: 2
    Last Post: 02-18-2013, 10:17 AM
  3. [SOLVED] Error checking
    By kello99 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-05-2012, 09:34 AM
  4. Error Checking
    By dshilan in forum Excel General
    Replies: 1
    Last Post: 11-05-2010, 02:18 PM
  5. Error checking
    By Cbrehm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2010, 07:25 PM
  6. error checking
    By ghadir14 in forum Excel General
    Replies: 6
    Last Post: 10-15-2007, 06:44 PM
  7. Error Checking
    By mworth01 in forum Excel General
    Replies: 1
    Last Post: 05-18-2006, 03:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1