Thursday, July 30, 2009

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 %26amp; 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?

What is the Visual Basic syntax to disable a field in form if a certain option is selected from a list box?
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
Reply: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
Reply: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
Reply:If List1.ListIndex = (whatever position your item to cause the disabling is) Then


txtNetwork.Enabled = False


Else:


txtNetwork.Enabled = True


End If
Reply:assuming the network 'field' is a textbox, it's simply





If Listbox.selecteditem = "PSF" then


TextboxNetwork.enabled = False


End If
Reply: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.


No comments:

Post a Comment