Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2006
    Posts
    25

    Unanswered: How to disable a text box depending on the option group selected

    Hi,
    I'm using Access 97, and trying to have users enter data in a text box only if certain situation exists in an option box, otherwise the text box to be disabled and greyed out.
    Tried using macro and module, but I can't get it to work. Can you help?

  2. #2
    Join Date
    Aug 2006
    Location
    Thailand
    Posts
    12
    Pradon in my English.
    I don't sure that I understand your topic.Look this easy one
    ....
    Private Sub Form_Load()
    Text1.Enabled = False
    End Sub
    ' I creat Frame0 as option's groub that frame0.value depend on option's value
    Private Sub Frame0_AfterUpdate()
    If Frame0.Value <> "" Then
    Text1.Enabled = True
    End If
    End Sub
    ...

  3. #3
    Join Date
    Aug 2006
    Posts
    25
    Thanks for your help polngpole, but I couldn't make it to work.
    Today I'm working from home with Access 2000, and my wizard is not working. Instead of using option boxes. I'm using combo box.
    I'm enclosing the database. Perhaps you can look at it and help me that way.

    This is what I'm trying to do. I want expiration boxes to be greyed out if the value in the Permit Required field is "Registration Only" or "2"
    Attached Files Attached Files

  4. #4
    Join Date
    Jul 2004
    Location
    Southampton, UK
    Posts
    368
    Change your code to:

    Private Sub Combo6_AfterUpdate()
    If Me!Combo6.Value = "2" Then
    Me!Expiration.Enabled = False
    End If
    End Sub

    The Me! refers to the current object i.e. the form you are using.

    Note that the above will disable the expiration field but won't enable it (say fr other values). You need more code for that e.g. add an ELSE ...

    Also note that once you have selected "2", the field will remain disabled regardless of what record you are on and even if you exit and re-enter the form. So you need a way of running this code each time you move to another record. This is easily achieved by adding the same code to the OnCurrent event for the form.

    hth
    Chris

  5. #5
    Join Date
    Aug 2006
    Posts
    25

    Need additional help

    Chris,

    Thanks for your efforts. However it didn't work for me.
    This is what I entered.

    Private Sub Combo6_AfterUpdate()
    If Me!Combo6.Value = "2" Then
    Me!Expiration.Enabled = False
    ElseIf Me!Combo6.Value = "1" Then
    Me!Expiration.Enabled = True
    End If
    End Sub

    The expiration field is not getting disabled when the combo6 value is "2", and even if it did, you're saying that the field will remain disabled regardless of what record I'll be on, and even if I exit and re-enter the form.
    To fix this problem, you're saying that I need a way of running this code each time I move
    to another record by adding the same code to the
    OnCurrent event for the form.
    I don't see the OnCurrent event option for the form.

    I've taken VB years ago, but never used it. I'm working on a project at work, and need to have this thing working.
    I'm sure it's something very simple, but when it doesn't work, it creates lots of stress.
    Can you please help me? Write the whole code for me if possible.
    Help!

  6. #6
    Join Date
    Jul 2004
    Location
    Southampton, UK
    Posts
    368
    I took another look at your db. I notice that your query uses RequiredDescription from the tblPermitRequired. I've removed this from the query and replaced with PermitRequiredID from tblPermits. So the query is based on one table now, not two. I've then modified your combo box to use tblPermitRequired as the dropdown list and changed it to PermitRequiredID as the source. In particular it will show both the ID and description (but only the ID will be stored). It doesn't answer why your code isn't working though.

    I've changed the code to what I proposed and also added the On Current code.

    Quote Originally Posted by comppal
    I don't see the OnCurrent event option for the form.
    There are several ways to get to the On Current event but here's one. Open the form in design view. Then right click on the small grey box that is where the two rulers meet and select properties (the same can be achieved by right-clicking in the header bar of the form window). In the Event properties you'll find On Current.

    There was a form load event. I removed this as it wasn't doing anything.

    I couldn't really see anything that would stop the code working. It worked straight away for me. I see you are using Access 2000 so maybe the syntax is slightly different. I'm using 2003 and it seems to accept any form reference even without the me!. You could try:

    me.Combo6.value

    or
    [forms]![frmPermits]![Combo6].value

    revised d/b attached

    Chris
    Attached Files Attached Files

  7. #7
    Join Date
    Nov 2003
    Posts
    1,487
    Your sample back to you with some changes....

    .
    Attached Files Attached Files
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  8. #8
    Join Date
    Aug 2006
    Posts
    25

    Smile It Works!

    I love you guys. You've made my day. Tomorrow I can make the changes at work before my meeting with my manager.

    Thank you to both of you for going out of your way to help me.

    The codes work.

    I especially like what CyberLynx did, although the code looks a little foreign to me. The expiration field is being disabled when I go to the record where "Required" field value ="2", without having to use Combo6_AfterUpdate() feature.

    Thank You! Thank You!


    Note: By the way, yesterday it was my first time I join a forum, and I'm glad I did. I guess you'll see me here more often.

  9. #9
    Join Date
    Nov 2003
    Posts
    1,487
    although the code looks a little foreign to me. The expiration field is being disabled when I go to the record where "Required" field value ="2", without having to use Combo6_AfterUpdate() feature.
    As Chris had mentioned earlier, this can be done through the Form's OnCurrent event which is exactly how it is done within the returned sample.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


Posting Permissions

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