Results 1 to 4 of 4
  1. #1
    hwong is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2012
    Posts
    13

    Text Box Controls Problem

    Greeting All!
    I have a question that if I have many text box, say A - Z, in a form, how can I set if any 1 of them was entered with value and all the others become disabled / locked? It is quite silly to set 26 similar procedures and I think there must be a easier way.
    Would anyone help me?



    Thanks x 100!

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    What you need to do is use the Controls Collection.
    Here's a page that goes through a few examples:
    http://www.tek-tips.com/faqs.cfm?fid=5010
    You should look for examples that show how to identify whether the control is a Text Box - and then modify the code so that you can set the Property of each Text Box to whatever you need it to be.
    For instance:
    Code:
    Dim ctl As Control
    
    For Each ctl In Me.Controls
        If (ctl.ControlType = acTextBox) Then
            If ctl.Value Is Null Then
                ctl.Enabled = False
            End If
        End If
    Next ctl
    Hope this helps. All the best!!

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Actually, in VBA code

    If ctl.Value Is Null Then

    would have to be

    If IsNull(ctl.Value) Then

    Robeen has given you the general type of code for looping through all Textboxes on a Form and taking some action, but exactly how you'd need to implement this code depends on exactly what your situation is, something you haven't shared with us! A clear explanation of what you're attempting to do would help us help you!

    For most situations, you'd have to at least Call a Function to execute this code, from the AfterUpdate event of each of the 26 Textboxes. It would be a simple

    Call MyFunctionName

    but it would have to be in the AfterUpdate event of each Textbox.

    If the situation simply required that once a Value was entered into any Control, all other Controls would become Disabled and stay Disabled, for ever and ever, you could put the code in the Form_Dirty event.

    Like I said, it just depends on your exact situation!

    As Oliver Twist requested, "Please, sir, I want some more!"

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    hwong is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2012
    Posts
    13
    Thanks both!!!! I will try~

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

Similar Threads

  1. Replies: 2
    Last Post: 08-07-2012, 02:02 PM
  2. Problem with Russian text in Access
    By milakovsky in forum Access
    Replies: 0
    Last Post: 01-20-2012, 02:33 PM
  3. Text Box controle problem in report
    By taahir321 in forum Reports
    Replies: 7
    Last Post: 09-29-2011, 08:31 AM
  4. formula in text box problem
    By kwooten in forum Reports
    Replies: 7
    Last Post: 09-12-2011, 08:19 AM
  5. Text/Number Relationship Problem
    By Luke in forum Access
    Replies: 4
    Last Post: 07-07-2011, 11:29 AM

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