Results 1 to 13 of 13

Thread: Hellpp!!!

  1. #1
    Join Date
    May 2012
    Posts
    89

    Unanswered: Hellpp!!!

    Hi i have a problem with a simple(single Form) i have a view text boxes of the form that i want to be sure to be filled in completely and i have a buttun that confirms and then (saves) close the form...

    The confirm button (Visible = False)

    Now i want to make the butto n fisible when ALL the text boxes have been entered a Value and i have a statement of this for it:

    Before_Update_textbox1

    If (IsNull)(me.textbox1.Value) Then
    ConfirmButton = False
    Else
    ConfirmButton = True
    End If
    End Sub

    Before_Update_textbox2

    If (IsNull)(me.textbox2.Value) Then
    ConfirmButton = False
    Else
    ConfirmButton = True
    End If
    End Sub

    And so on for all the text boxes, but when TextBox1 has an Value then the button becomes True but i want it to be True when all the boxes have a Value and not just 1 text box...

    plz tel me what i am doin wrong...

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Here's a solution. Paste the following code in the form module:
    Code:
    Option Compare Database
    Option Explicit
    
    Private m_colTextbox As Collection
    
    Private Function CheckCompleted()
    
        Dim ctl As Control
        Dim booVisible As Boolean
        
        booVisible = True
        For Each ctl In m_colTextbox
            If Nz(ctl.Value, "") = "" Then
                booVisible = False
                Exit For
            End If
        Next ctl
        Me.ConfirmButton.Visible = booVisible
        
    End Function
    
    Private Sub GatherControls()
    
        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 Sub Form_Open(Cancel As Integer)
    
        GatherControls
        
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    To use your approach of validating all Controls each time a given Control is populated, you'd have to check all Controls each time a given Control was populated, a rather cumbersome process! Also, if the user thinks a Control isn't needed and leaves it blank, he's left with a Form that is simply sitting there, with no way to exit.

    Basing formatting on the Validation of Multiple Controls really should be done in the Form_BeforeUpdate event, popping a Messagebox to the user and preventing saving the Record until all Controls are filled in. Something like this:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
     If Nz(Me.Control1,"") = "" Then
       MsgBox "Control1 Must Not Be Left Blank!"
       Cancel = True
       Control1.SetFocus
       Exit Sub
     End If
     
    If Nz(Me.Control2, "") = "" Then
       MsgBox "Control2 Must Not Be Left Blank!"
       Cancel = True
       Control2.SetFocus
       Exit Sub
     End If
    
    End Sub
    There are other ways, involving looping through all the Controls that are required, but the above is a simple way to address your problem.

    Linq ;0)>
    Last edited by Missinglinq; 05-22-12 at 11:55.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    another technique would be to set the background colour of the affected controls so the user can see in one hit which controls still need values
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    There is no reason for not checking all controls every time one changes. I performed the following test on an average machine (XP SP3, Access 2003 SP3, CPU: Intel Core2 Duo E6850 3Ghz, physical memory 2048 Mo 800 MHz DDR2 Synchronous). There were 30 textbox controls on the form:
    Code:
    Private Declare Function GetTickCount Lib "Kernel32" () As Long
    Private m_colTextbox As Collection
    
    Private Function CheckCompleted()
    
        Dim ctl As Control
        Dim booVisible As Boolean
        Dim i  As Long, j As Long
        Dim lngtstart As Long
        
        For i = 1 To 50
            lngtstart = GetTickCount
            For j = 1 To 1000
                booVisible = True
                For Each ctl In m_colTextbox
                    If Nz(ctl.Value, "") = "" Then
                        booVisible = False
                        Exit For
                    End If
                Next ctl
                Me.ConfirmButton.Visible = booVisible
            Next j
            Debug.Print i, GetTickCount - lngtstart
        Next i
        
    End Function
    The average time to check all textbox controls in the collection was 0,0225 millisecond.
    Attached Thumbnails Attached Thumbnails Test.jpg  
    Have a nice day!

  6. #6
    Join Date
    May 2012
    Posts
    89
    Quote Originally Posted by Sinndho View Post
    Here's a solution. Paste the following code in the form module:
    Code:
    Option Compare Database
    Option Explicit
    
    Private m_colTextbox As Collection
    
    Private Function CheckCompleted()
    
        Dim ctl As Control
        Dim booVisible As Boolean
        
        booVisible = True
        For Each ctl In m_colTextbox
            If Nz(ctl.Value, "") = "" Then
                booVisible = False
                Exit For
            End If
        Next ctl
        Me.ConfirmButton.Visible = booVisible
        
    End Function
    
    Private Sub GatherControls()
    
        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 Sub Form_Open(Cancel As Integer)
    
        GatherControls
        
    End Sub
    This makes no sense to me at all...
    if paste it into the form module but nothing happend not an error or something...
    maybe you can clear this up for me...
    the first textbox is called Firma
    the second textbox is called: Achternaam
    And the last text box is called: Voornaam
    The confirm button is called: btnConstructorOK
    Hope you can help me with this...

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by Rubberducksucker View Post
    the first textbox is called Firma
    the second textbox is called: Achternaam
    And the last text box is called: Voornaam
    The confirm button is called: btnConstructorOK
    Hope you can help me with this...
    1. The name of the textbox controls does not matter: every Textbox control in the form is added to the m_colTextbox collection.

    2. If the name of the Command button is "btnConstructorOK", then change the code accordingly:
    Code:
    Me.btnConstructorOK.Visible = booVisible
    Have a nice day!

  8. #8
    Join Date
    May 2012
    Posts
    89
    Quote Originally Posted by Sinndho View Post
    1. The name of the textbox controls does not matter: every Textbox control in the form is added to the m_colTextbox collection.

    2. If the name of the Command button is "btnConstructorOK", then change the code accordingly:
    Code:
    Me.btnConstructorOK.Visible = booVisible
    It works perfect, bud i try to apply this to the Enable function bud the it wont do it ...
    What is the code for that..??

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    to the enable function? which one is that then
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If you mean that you want to use the Enabled property of the command button btnConstructorOK instead of its Visible property, change:
    Code:
    Me.btnConstructorOK.Visible = booVisible
    to:
    Code:
    Me.btnConstructorOK.Enabled = booVisible
    In such a case, you should rename the variable booVisible to booEnabled everywhere in the code of the function CheckCompleted(), so:
    Code:
    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!

  11. #11
    Join Date
    May 2012
    Posts
    89
    Quote Originally Posted by Sinndho View Post
    If you mean that you want to use the Enabled property of the command button btnConstructorOK instead of its Visible property, change:
    Code:
    Me.btnConstructorOK.Visible = booVisible
    to:
    Code:
    Me.btnConstructorOK.Enabled = booVisible
    In such a case, you should rename the variable booVisible to booEnabled everywhere in the code of the function CheckCompleted(), so:
    Code:
    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
    Great thanks!!!!

  12. #12
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

  13. #13
    Join Date
    May 2012
    Posts
    89
    Quote Originally Posted by Sinndho View Post
    You're welcome!

    If got an other question hope you can help me with it...
    ------------------------------------------------------------------------
    the data base is for registration of people who are in the building, and from what time and to what time they are leaving...

    I have a form (mainform) where i have 2 buttons 1 for adding a record when some1 comes in. and 1 button for when some1 gets out.
    Both buttons have textboxes to add time and name ext ext.
    And i have made a query with all the info what i have displayed on a (Sub)form
    Bud when i add a name (record) din or out, the data is not updated on the (query)form to see the data i have put in i need to reopen the mainform...

    So can some1 tell me how the form what displays the info from the query to be auto updated every time i add some data or some thing similar...

Posting Permissions

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