Results 1 to 6 of 6
  1. #1
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72

    How to see if all fields of the form are blank.

    Hi guys,

    for an if statement i want to see if all the fields of a form are empty. Is there an easy way to do it instead of checking every field separately.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    None that I know.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You could iterate the controls using a for each statement.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Iterative or not, still checking content of each field/control. Iterative code is just more compact. Relies on some common feature of the controls because probably want to ignore labels and subforms if any.

    If the controls have a similar naming structure, like Data1, Data2, Data3, etc. and you have say 10 controls to check:

    booEmpty As Boolean
    For i = 1 to 10
    If IsNull(Me.Controls("Data" & i)) Then booEmpty = True
    Next
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Perhaps if you could give us an idea of your actual goal, here, we could give you a better answer. For a starter, why are you checking whether or not all Controls are unpopulated? Also, is this a bound Form?

    Linq ;0)>

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I agree with Linq that more insight is needed to provide the best solution.


    Quote Originally Posted by June7 View Post
    ...If the controls have a similar naming structure, like Data1, Data2, Data3, etc. and you have say 10 controls to check:...
    That's kinda what I was thinking only using the Form's collection vs. a strongly typed approach. So something like....

    Code:
    Dim ctl as Control
        For Each ctl In Me.Controls
                'Change the backcolor
                If IsNull(ctl.Value) Then
                    Ctl.Backcolor = 255
                End If
        Next ctl
    The above If Then statement could be nested within another If Then or Case Select. You could verify the control type using something like
    If ctl.ControlType = acTextbox Then

    Another approach I use is to employ the Tag property of controls on my forms. So I will place keywords in the Tag property for controls that I want to treat similarly. The following example shows how I display multiple labels, but not all labels, on a form.


    Code:
    Dim ctl as Control
        For Each ctl In Me.Controls
                'Show the asterisk
                If InStr(ctl.Tag, "Asterisk") <> 0 Then
                    ctl.Visible = True
                End If
        Next ctl

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

Similar Threads

  1. Blank Fields
    By billgyrotech in forum Reports
    Replies: 12
    Last Post: 04-18-2013, 03:36 PM
  2. Replies: 3
    Last Post: 01-08-2013, 02:41 PM
  3. Replies: 5
    Last Post: 06-11-2012, 08:47 AM
  4. no blank fields
    By imintrouble in forum Forms
    Replies: 2
    Last Post: 10-24-2011, 10:21 AM
  5. Replies: 2
    Last Post: 02-03-2011, 12:41 PM

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