Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2004
    Location
    Houston, TX
    Posts
    29

    Question Unanswered: Disable Text Box

    I need some help with the following situation:

    I have a text box that is used to enter a completion date. I would like to disable this text box once a value has been entered into it. It would also be nice to be able to re-enable it at some point, such as through a cmd button or something.

    If you have any ideas on how I can do this please respond.

    Thanks,

    Mr. Research

  2. #2
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Form code

    During the OnCurrent event of the form add this code

    If not isnull(me.NAMEOFFIELDWITHDATEIN) Then

    me.NAMEOFFIELDWITHDATEIN.enabled = false

    Else

    me.NAMEOFFIELDWITHDATEIN.enabled = true

    Endif

    For your command button:

    me.NAMEOFFIELDWITHDATEIN.enabled = true
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  3. #3
    Join Date
    Jan 2004
    Location
    Houston, TX
    Posts
    29

    Re: Form code

    Ok, next scenario, is there a way to enable or disable all fields on a form? And can one change the font properties of a disabled field?

    Originally posted by garethdart
    During the OnCurrent event of the form add this code

    If not isnull(me.NAMEOFFIELDWITHDATEIN) Then

    me.NAMEOFFIELDWITHDATEIN.enabled = false

    Else

    me.NAMEOFFIELDWITHDATEIN.enabled = true

    Endif

    For your command button:

    me.NAMEOFFIELDWITHDATEIN.enabled = true

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Re: Form code

    Originally posted by MrResearch
    Ok, next scenario, is there a way to enable or disable all fields on a form? And can one change the font properties of a disabled field?
    Try this function

    Sub EnableDisable_TextFields(frm As Form, lEnable As Boolean)
      Dim ctl As Control
       For Each ctl In frm.Controls
        If ctl.Name = acTextBox Then
         Select Case lEnable
         Case True
          ctl.Enabled = True

         Case False
          ctl.Enabled = False
         End Select
        End If
       Next ctl
    End Sub


  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    I tasted that function, it has an error
    here it is again

    Sub EnableDisable_TextFields(frm As Form, lEnable As Boolean)
      Dim ctl As Control
       For Each ctl In frm.Controls
       Select Case lEnable
        Case True
         ctl.Enabled = True

        Case False
         ctl.Enabled = False
       End Select
       Next ctl
    End Sub

    Also you have to set the focus to another Control, which will not be disabled, before you start this function.

  6. #6
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Sorry again, here is the code this time I tested it

    Sub EnableDisable_Form(frm As Form, lEnable As Boolean)
      Dim ctl As Control
       For Each ctl In frm.Controls
        If ctl.ControlType = acTextBox Then
         Select Case lEnable
          Case True
           ctl.Enabled = True

          Case False
           ctl.Enabled = False
         End Select
        End If
       Next ctl
    End Sub

  7. #7
    Join Date
    Nov 2003
    Posts
    1,487
    And to change the font during the disable/enable process, add this to Hammbakka's code just before it is enabled or disabled:

    Ctrl.FontName = "TheFontName"

    The code would look like:

    Code:
    Sub EnableDisable_Form(frm As Form, lEnable As Boolean)
      Dim ctl As Control
       For Each ctl In frm.Controls
        If ctl.ControlType = acTextBox Then
         Select Case lEnable
          Case True
           ctl.Enabled = True
           'Change font to what you want when Enabled.
           Ctrl.FontName = "TheFontName"
    
          Case False
           'Change font to what you want when disabled.
           Ctrl.FontName = "TheFontName"
           ctl.Enabled = False
         End Select
        End If
       Next ctl
    End Sub
    Last edited by CyberLynx; 01-15-04 at 03:55.

  8. #8
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Thank you CyberLynx for completing the function, also MrResearch can send the fontname as a Parameter of the Sub so the sub should be like:
    Sub EnableDisable_TextFields(frm As Form, lEnable As Boolean, FontName as String)

  9. #9
    Join Date
    Nov 2003
    Posts
    1,487
    You are absolutely right Hammbakka, and MrResearch could go even a little further and make the font entry optional so that it doesn't need to be entered every time the function is called:

    Code:
    Sub EnableDisable_TextFields(frm As Form, lEnable As Boolean, Optional FontName as String)
    WOW...MrResearch...I bet you go more than what you bargained for, right Hammbakka

  10. #10
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Absolutely right CyberLynx and good luck MrResearch

  11. #11
    Join Date
    Jan 2004
    Location
    Houston, TX
    Posts
    29
    Thanks everyone! This is exactly what I was looking for. I knew this could be accomplished through the for...each command but was not sure how to implement it.

    Thanks!


    Originally posted by hammbakka
    Absolutely right CyberLynx and good luck MrResearch

Posting Permissions

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