Results 1 to 10 of 10
  1. #1
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46

    Question Unanswered: Disabling a Text Box after user entry?

    Hi Guy and Gals,

    I have come a cross a problem that I hope you can help with, I have a form which users enter additional information into.

    I am looking for a way of setting a text box to disabled when the field is not empty/has a value, as the text or value entered into this box will not be standardised (I assume this would be achieved via the AfterUpdate & onCurrent properties of the text box).

    I do not want to "lock" the entry in the table just disable or lock (prefer disable so it greys it out) the field on a form so once it is filled only a user with access to the table of an "edit" form can alter its contents.

    The hope is that once the user enters a value and saves the record (already have a script that will undo any changes with a prompt "Do you wish to save - No will clear any additions to this record, Yes will save & close form" would like to add a cancel option in future), that field will automatically be disabled and not allow any changes or additions to it.

    Hope that makes sense!

    Thanks!

    Mike

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    You are right, just use the AfterUpdate and OnCurrent event procedures of the form to modify the Enabled property of the text box object.

    EG

    Code:
    If Me.ControlName > "" Then
       Me.ControlName.Enabled = False
    Else
       Me.ControlName.Enabled = True
    End If
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46
    Thanks for that, getting "Run-time Error '2164': You can't disable a control while it has focus." when I click out of the box?

    Highlighted:
    Code:
    Me.ControlName.Enabled = False
    I tried using the code in the onLostFocus to no avail
    Last edited by setab; 07-14-08 at 11:36.

  4. #4
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46
    (I have changed the "ControlName" to fit my text boxes)

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Just set the focus to some other field at the top of the code...

    Me.ControlName.SetFocus
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46
    Once again StarTrekker... Legend.

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Most welcome
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46
    Hello, the code above is still working great, I have decide to use this on several fields as it is really fit for my uses.

    I was just wondering if there is a way this can be made a general "condition" of the page, rather than having the code repeated multiple times for each text box?

    Thanks! Mike

  9. #9
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Not that I am aware of. You can, however, modularise. Use ActiveControl rather than being specific about which control you're working with and then you should be able to minimise the amount of repeated coding.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  10. #10
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46
    I have tried simply changing the name of the current txtbox code that is working to "ActiveControl", which doesn't work, do I need to set it from me.ActiveControl to screen.ActiveControl? And if so what other conditions do I need to set?

    Thanks!

Posting Permissions

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