Results 1 to 2 of 2

Thread: CheckCompleted

  1. #1
    Join Date
    May 2012
    Posts
    89

    Red face Unanswered: CheckCompleted

    I have a code for a form when all textboxes are filled the button should be "Enabled" but it's not working, anybody know how and why???

    Private Function CheckCompleted()
    Dim ctl As Control

    Dim booEnabled As Boolean
    booEnabled = True
    For Each ctl In m_colTextbox
    If Nz(ctl.Value, "") = "" Then
    booEnabled = False

    Exit For
    End If
    Next ctl
    Me.ConfirmButton.Enabled = booEnabled
    End Function

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    This should work, provided that the Collection m_colControl is properly initialized. Here's a complete example:
    Code:
    '
    ' Class Module of the Form
    '
    Option Compare Database
    Option Explicit
    
    Private m_colTextBox As Collection
    
    Private Sub Form_Current()
    
        CheckCompleted
        
    End Sub
    
    Private Sub Form_Open(Cancel As Integer)
    
        Dim ctl As Control
        
        Set m_colTextBox = New Collection
        For Each ctl In Me.Controls
            If ctl.ControlType = acTextBox Then
                m_colTextBox.Add ctl
                ctl.AfterUpdate = "=CheckCompleted()"
            End If
        Next ctl
        
    End Sub
    
    Private Function CheckCompleted()
    
        Dim ctl As Control
        Dim booEnabled As Boolean
        
        booEnabled = True
        For Each ctl In m_colTextBox
            If Nz(ctl.Value, "") = "" Then
                booEnabled = False
                Exit For
            End If
        Next ctl
        Me.ConfirmButton.Enabled = booEnabled
        
    End Function
    Have a nice day!

Posting Permissions

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