Listbox Select/DeSelect

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

DS,

Here is some code that I know will work:
If Me.TxtNewSataion<> Me.LstTerminal Then
Me.TxtNewSataion= Me.LstTerminal
ElseIf Me.TxtNewSataion= Me.LstTerminal Then
Me.LstTerminal .Value = Null
Me.TxtNewSataion= 0
End If
 
I have a Listbox. When you click on it, it fills a textbox with the
contents of column(0).

What I would like to do is if you select a new record in the listbox it
fills in the textbox, however if you select the record that is currently
highlighted it deselects that record and inputs a 0 value into the
textbox. This is what I have and it is woefully not working.

Private Sub ListTerminal_Click()
Dim i As Integer
i = Me.ListTerminal.Column(0)

If i <> Me.TxtStation Then
Me.ListTerminal.Selected(i) = True
Me.TxtStation = Me.ListTerminal.Column(0)
ElseIf i = Me.TxtStation Then
Me.ListTerminal.Selected(i) = False
Me.CmdHide.SetFocus
End If
End Sub

Thanks
DS
 
DS said:
I have a Listbox. When you click on it, it fills a textbox with the
contents of column(0).

What I would like to do is if you select a new record in the listbox it
fills in the textbox, however if you select the record that is currently
highlighted it deselects that record and inputs a 0 value into the
textbox. This is what I have and it is woefully not working.

Private Sub ListTerminal_Click()
Dim i As Integer
i = Me.ListTerminal.Column(0)

If i <> Me.TxtStation Then
Me.ListTerminal.Selected(i) = True
Me.TxtStation = Me.ListTerminal.Column(0)
ElseIf i = Me.TxtStation Then
Me.ListTerminal.Selected(i) = False
Me.CmdHide.SetFocus
End If
End Sub

Thanks
DS
OK I figured this out. But is it good? Or is there a better way?
Thanks
DS
 
DS said:
I have a Listbox. When you click on it, it fills a textbox with the
contents of column(0).

What I would like to do is if you select a new record in the listbox it
fills in the textbox, however if you select the record that is currently
highlighted it deselects that record and inputs a 0 value into the
textbox. This is what I have and it is woefully not working.

Private Sub ListTerminal_Click()
Dim i As Integer
i = Me.ListTerminal.Column(0)

If i <> Me.TxtStation Then
Me.ListTerminal.Selected(i) = True
Me.TxtStation = Me.ListTerminal.Column(0)
ElseIf i = Me.TxtStation Then
Me.ListTerminal.Selected(i) = False
Me.CmdHide.SetFocus
End If
End Sub

Thanks
DS
Forget to paste the solution :)
Me.TxtNewStation = Me.ListTerminal.Column(0)
If Me.TxtNewStation = Me.TxtStation Then
Me.ListTerminal = ""
Me.TxtNewStation = -2
Me.TxtStation = -2
Me.CmdHide.SetFocus
Else
Me.TxtStation = Me.ListTerminal.Column(0)
End If
 
Mr said:
DS,

Here is some code that I know will work:
If Me.TxtNewSataion<> Me.LstTerminal Then
Me.TxtNewSataion= Me.LstTerminal
ElseIf Me.TxtNewSataion= Me.LstTerminal Then
Me.LstTerminal .Value = Null
Me.TxtNewSataion= 0
End If
U-Bet!!! Works great!
Thanks
DS
 
Back
Top