Latest Lists

What is the Visual Basic syntax to disable a field in form if a certain option is selected from a list box?

I have a list box that has 2 options: PSF & QTC. If PSF is selected, I want the Network field to be disabled. If QTC is selected, I want the Sales Order to be disabled. Can someone help me with the syntax?

Public Comments

  1. assuming the network 'field' is a textbox, it's simply If Listbox.selecteditem = "PSF" then TextboxNetwork.enabled = False End If
  2. Private Sub List1_Click() If List1.text = "PSF" Then ,network field disaabled code here exit sub End If If List1.text = "QTC" Then ,Sales Order disaabled code here exit sub End If End Sub
  3. If List1.ListIndex = (whatever position your item to cause the disabling is) Then txtNetwork.Enabled = False Else: txtNetwork.Enabled = True End If
  4. The me keyword refers to the current form. You need to add this code on the change event (I think) of the options If me.PSF = true then me.networkfield.enabled =false end if If me.QTC = true then me.salesorderfield.enabled = false end if
  5. Here is a snippet............. Private Sub Form_Load() List1.AddItem "aa" List1.AddItem "bb" End Sub Private Sub List1_Click() If List1.Text = "aa" Then Text1.Enabled = False Else Text1.Enabled = True End If End Sub
  6. For VB.NET you can have a click event and then just do field.enabled = false; in your codebehind. If you were meaning vbscript...well you can do it in javascript in a similar way by doing document.form.field.enabled = false; in the onclick function of the field.
Powered by Yahoo! Answers