Results 1 to 9 of 9
  1. #1
    Vaibhav2015 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    14

    how to disable certain fields in Form?

    Hi,


    I want to disable certain fields after selecting option from combo box. option are "Yes" and "No". If I select "Yes" all fields must be editable and
    If I select"No" only specific two or three fields should be editable.

    can you please advice me how I can do that in Access Form.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    set the enabled value by looking at the combo value

    Code:
    sub cboBox_Afterupdate()
    
    
    txtName.enabled =  cboBox = "Yes"
    txtAddr.enabled =  cboBox = "Yes"
    txtCity.enabled =  false
    
    
    txtCode.enabled =  true
    end sub

  3. #3
    Vaibhav2015 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    14
    Hi,
    Can we add If condition in VBA code, for disabled the fields.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    that is the code. What IF do you want?
    the combo only has yes/no.

  5. #5
    Vaibhav2015 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    14
    Yes. I have added value list "yes","no" in combo box.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You can use an If, Then, Else statement to control the flow of statements. For example ...

    Code:
    If Me.ComboName.Value = "Yes" Then
    msgbox "You selected YES"
    Else
    msgbox "You selected NO"
    End If
    Since you have multiple controls that you want to edit properties for, I would suggest using an If Then Else statement in conjunction with a procedure that looped through all of the controls, identifying predefined controls and updating the properties accordingly.

  7. #7
    Vaibhav2015 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    14
    I tried below codes, but after selection 1 or 2 in combo box another text field is still enabled in both If condition.
    please advice.

    Private Sub Combo0_AfterUpdate()
    If Me.Combo0.Value = 1 Then


    Me.Text2.Enabled = False


    ElseIf Me.Combo0.Value = 2 Then


    Me.Text2.Enabled = True
    Me.Text2.SetFocus


    End If


    End Sub

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You might try inserting a message box to fire when the value of your combo changes. Have the message box display the value of the combo.

    Code:
    msgbox me.combo0.value
    
    If Me.Combo0.Value = 1 Then
    
     Me.Text2.Enabled = False
    
     ElseIf Me.Combo0.Value = 2 Then
    
     Me.Text2.Enabled = True
     Me.Text2.SetFocus
    
     End If

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Conditional Formatting can dynamically disable/enable data controls - no VBA needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-05-2013, 09:03 AM
  2. Replies: 8
    Last Post: 08-02-2012, 02:53 PM
  3. Replies: 1
    Last Post: 02-25-2011, 10:03 AM
  4. Disable fields based on another.
    By scottay in forum Forms
    Replies: 0
    Last Post: 08-10-2010, 05:40 PM
  5. disable/gray out fields
    By michaelpclisbee in forum Forms
    Replies: 2
    Last Post: 07-05-2009, 07:59 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