Visual Basic code for enabling and disabling text boxes in MS Access?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VBnewb13
    New Member
    • Jun 2010
    • 17

    Visual Basic code for enabling and disabling text boxes in MS Access?

    Hello all,

    I have been having some troubles figuring out how to do this. Naturally, I have looked through this forum and countless others, all yielding the same answers to my question... which for some reason I cannot get to work. I can't quite figure out what I'm doing wrong here.

    I am in the process of creating a search form that searches through a database using different parameters. This parameters are text boxes. Next to the text boxes are checkboxes. For example, I would like to have Text1 enabled when Checkbox1 is checked. Here is what I have so far:

    Code:
    Private Sub Check1_AfterUpdate()
    If Me.Check1 = True Then
    Me.text1.Enabled = True
    Else
    Me.text1.Enabled = False
    End If
    End Sub
    Keep in mind that I am doing this in MS Access 2007.

    I am open to any suggestions and greatly appreciate any help.

    Thanks,
    VBnewb13
  • patjones
    Recognized Expert Contributor
    • Jun 2007
    • 931

    #2
    Code:
    Private Sub Check1_AfterUpdate()
       Me.text1.Enabled = Me.Check1
    End Sub

    When I do this, I usually set the text box's default state to not enabled so that when the form first opens, it corresponds to the check box being unchecked. Alternatively you could set the check box default to checked. Either way, make sure the states correspond to each other on form open.

    Pat

    Comment

    • VBnewb13
      New Member
      • Jun 2010
      • 17

      #3
      That is brilliant, I see exactly what you are saying. I really can't get it to work for some reason. I'll detail exactly what I have set up:

      I have a form. On this form I have text1 and check1. I have the exact code you suggested.

      How do I set the default value of check1 to off.
      Me.check1.value = 0 ?
      Or what do I type in the data section of properties where it says default value?

      Thanks again

      Comment

      • patjones
        Recognized Expert Contributor
        • Jun 2007
        • 931

        #4
        In the form's On Open event you could certainly say Me.check1 = 0, or set it in the properties sheet in form design view.

        Pat

        Comment

        • vb5prgrmr
          Recognized Expert Contributor
          • Oct 2009
          • 305

          #5
          In VB, we have a constant...
          Code:
          If Me.Check1.Value = vbChecked Then
          '...
          So I wonder if you have the same in VBA...



          Good Luck

          Comment

          • VBnewb13
            New Member
            • Jun 2010
            • 17

            #6
            I figured it out. I had to enable some security options I guess. That's why when I initially created something it worked, but when I closed the db and reopened it nothing would work.

            thanks for your help though, it worked out great :)

            Comment

            Working...