Results 1 to 7 of 7
  1. #1
    m33hdy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jan 2019
    Posts
    3

    Enable Textbox if another combobox contains "Other"

    Hi all,



    Just wanted to clarify the VBA code required to enable a text box if another combobox contains the word "Other"?

    Click image for larger version. 

Name:	enable.jpg 
Views:	5 
Size:	98.5 KB 
ID:	36991

    The name of my combobox is "Cardiac" and the name of the textbox i wish to Enable is "Other". The code i'm using at the moment is as follows but doesen't seem to work

    Code:
    Private Sub Cardiac_AfterUpdate()If Me.Cardiac.Text = "other" Then
    Me.Other.Enabled = False
    Else
    Me.Other.Enabled = True
    End If
    End Sub
    Any help much appreciated

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    You need to use wildcards
    Change ="Other" to Like "*Other*"

    Then swop your true and false satements
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    m33hdy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jan 2019
    Posts
    3
    Thanks, you mean like this?

    Code:
    Private Sub Cardiac_procedures_or_conditions_Click()If Me.Cardiac.Text Like "*Other*" Then
    Me.Other.Enabled = True
    Else
    Me.Other.Enabled = False
    End If
    End Sub
    Not working for me

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    May just be an issue when you uploaded but it should be

    Code:
    Private Sub Cardiac_procedures_or_conditions_Click()
    If Me.CardiacProcedure Like "*Other*" Then
    Me.Other.Enabled = True
    Else
    Me.Other.Enabled = False
    End If
    End Sub
    This assumes your textboxes are called CardiacProcedure and Other.
    If not, modify as appropriate.
    If the names contain spaces enclose in square brackets []
    Do not use .Text in the code
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    m33hdy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jan 2019
    Posts
    3
    Thanks again. Still doesn't seem to work. I've made sure that my textboxes are named as per above (i.e. CardiacProcedure and Other)

    Click image for larger version. 

Name:	enable 1.jpg 
Views:	5 
Size:	171.7 KB 
ID:	36992

    Click image for larger version. 

Name:	enable 2.jpg 
Views:	5 
Size:	173.2 KB 
ID:	36993

    Click image for larger version. 

Name:	enable 3.jpg 
Views:	5 
Size:	90.0 KB 
ID:	36994

    code used:

    Code:
    Private Sub CardiacProcedure_Afterupdate()If Me.CardiacProcedure Like "*Other*" Then
    Me.Other.Enabled = True
    Else
    Me.Other.Enabled = False
    End If
    End Sub
    I changed the Click event to AfterUpdate

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    AfterUpdate event is correct. Not sure how I missed that before.
    Check that it says Event Procedure next to the after update event in the property sheet.

    If that's not the issue then I'm baffled
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #7
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    What is the bound column data for the CardiacProcedure combo ?
    Is it "Other" or is its row source a table and your storing the ID ?

    Also slightly worried in your picture that you have tables called Treatment 1 , 2, 3, 4 and 5...
    This sounds like the same basic data being stored in separate tables which is a probably a bad idea. Can you elaborate?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Replies: 8
    Last Post: 06-12-2018, 03:05 PM
  2. Replies: 5
    Last Post: 12-04-2015, 10:19 AM
  3. Replies: 1
    Last Post: 09-03-2014, 03:27 AM
  4. Replies: 2
    Last Post: 03-23-2012, 05:09 AM
  5. Disable security warning to "enable content"?
    By Heatshiver in forum Security
    Replies: 2
    Last Post: 02-03-2012, 02:26 PM

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