listbox selection

A

asa

Hi

I've a listbox which is unbound and a textbox. The textbox has a control
source which is tied to a column and it is not editable. Only when user has
selected a particular item eg:ItemA from the listbox, I want to make the
textbox editable for user to enter some info.
Not sure how to do it. Help Pls....
 
W

Wayne Morgan

When you say the textbox isn't editable, why isn't it? Have you set the
Enabled or Locked property of the textbox to prevent editing or is it's
Control Source not editable? If the Control Source isn't editable, then
you'll have to fix the Control Source, probably a query, to make it
editable. However, if you've set the Enable and/or Locked properties for the
textbox to prevent users from editing it, then that can be changed when a
selection is made in the listbox.

If the MultiSelect property of the listbox is set to None:
In the AfterUpdate event of the listbox, check to see if the Value is Null,
if not, then enable the textbox.

Example:
If IsNull(Me.lstMyListbox) Then
Me.txtMyTextbox.Enabled = False
Me.txtMyTextbox.Locked = True
Else
Me.txtMyTextbox.Enabled = True
Me.txtMyTextbox.Locked = False
End If

Use the Enable and/or Locked properties in the code, depending on which of
these you've used to disable editing.

If the MultiSelect Property of the listbox is set to Simple or Extended:
In the AfterUpdate event of the listbox, check to see how many items are
selected. If one or more, then enable the textbox.

Example:
If Me.lstMyListbox.ItemsSelected.Count = 0 Then
Me.txtMyTextbox.Enabled = False
Me.txtMyTextbox.Locked = True
Else
Me.txtMyTextbox.Enabled = True
Me.txtMyTextbox.Locked = False
End If

You may also need to do this in the form's Current event.
 
Top