Results 1 to 5 of 5
  1. #1
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352

    Question For/Next Control Statement Issues

    I have this code run behind my submit button to double check that all txt boxes and cbo's are filled in before submitting the data.


    Code:
    Dim c As Control
    For Each c In Me.Controls
        If c.ControlType = acTextBox Then
            If IsNull(c.Value) Or c.Value = "" Then
                MsgBox "Please fill the form to completion before submission.", vbOKOnly, "Missing Information"
                Exit Sub
            End If
        If c.ControlType = acComboBox Then
            If IsNull(c.Value) Or c.Value = "" Then
                MsgBox "Please fill the form to completion before submission.", vbOKOnly, "Missing Information"
                Exit Sub
            End If
        End If
    End If
    Next
    However I get the error "Next without For"

    EDIT: Updated code, all I did was add an extra 'End if' before the Next. Not sure why this worked but it did

    The code works well for all null textboxes but does not catch if the combo boxes are null. Any ideas?
    Last edited by nick404; 07-29-2015 at 10:35 AM. Reason: Edit to code, additional information

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    EDIT: Updated code, all I did was add an extra 'End if' before the Next. Not sure why this worked but it did
    You need and END IF for every IF ... THEN, if you do not complete statement all on one line.
    It looks like you didn't have one originally for your first "IF ... THEN" statement.

  3. #3
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Oh yes you are right the very first one was neglected.

    The code catches any null textboxes and presents the message just fine, but it does not seem to work for the combo boxes.
    Any one have a clue as to why?

  4. #4
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    *Resolved.
    If anyone is wondering I had to move my bottom End If to the top to the very fist IF statement.
    Code:
    Dim c As Control
    For Each c In Me.Controls
        If c.ControlType = acTextBox Then
            If IsNull(c.Value) Or c.Value = "" Then
                MsgBox "Please fill the form to completion before submission.", vbOKOnly, "Missing Information"
                Exit Sub
            End If
        End If
        If c.ControlType = acComboBox Then
            If IsNull(c.Value) Or c.Value = "" Then
                MsgBox "Please fill the form to completion before submission.", vbOKOnly, "Missing Information"
                Exit Sub
            End If
        End If
    End If -> moved from here to where blue End If is
    Next

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    *** deleted ***

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 10-20-2014, 08:43 PM
  2. Check box to if statement issues
    By wlkr.jk in forum Programming
    Replies: 3
    Last Post: 07-30-2014, 05:41 AM
  3. Update unbound control in report based on if statement
    By echomania in forum Programming
    Replies: 6
    Last Post: 11-23-2012, 11:37 PM
  4. Replies: 9
    Last Post: 05-07-2012, 06:11 PM
  5. IIF statement in control source of text box
    By LilMissAttack in forum Reports
    Replies: 11
    Last Post: 08-18-2011, 10:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums