list box to text box (1 Viewer)

cos

Registered User.
Local time
Today, 07:42
Joined
Jul 13, 2012
Messages
81
how can i show a selected by the user record from a list box in an unbound text box? i made a listbox which has two columns and shows various info, and i need the selected record, what appears to be in column two to be shown in my text box..

any ideas?
 

pr2-eugin

Super Moderator
Local time
Today, 07:42
Joined
Nov 30, 2011
Messages
8,494
Try using this..
Code:
Me.[COLOR=Blue]unboundTextBoxName[/COLOR] = Me.[COLOR=Blue]ListBoxName[/COLOR].Column(1, Me.[COLOR=Blue]ListBoxName[/COLOR].ItemsSelected)
Blue bits needs to change, as it is in the Second column and List box are 0 based so you use 1 to reference 2nd column.
 

Trevor G

Registered User.
Local time
Today, 07:42
Joined
Oct 1, 2009
Messages
2,341
Something like this. Select the list box in design view and open the properties then click the Event tab and use the On Click Event

Private Sub List0_Click()
Me.txtName.Value = Me.List0.Column(1)

End Sub
 

cos

Registered User.
Local time
Today, 07:42
Joined
Jul 13, 2012
Messages
81
i have no idea where to put that code.. as i tried and nothin works.. =/
 

Trevor G

Registered User.
Local time
Today, 07:42
Joined
Oct 1, 2009
Messages
2,341
Read my instructions and you will be able to do what you want.

Open the form in design view and select the ListBox Open the properties and then the Event Tab, and then the On Click Event and use the Ellipse button and select Code Builder then you add the code inside there.
 

cos

Registered User.
Local time
Today, 07:42
Joined
Jul 13, 2012
Messages
81
and for yours Trevor, i get this error:

"The expression On Click you entered as the event property setting produced the following error: Invalid outside procedure."
 

Trevor G

Registered User.
Local time
Today, 07:42
Joined
Oct 1, 2009
Messages
2,341
OK Copy what code you have added and also list the 2 named objects, i.e what have you called the listbox and the textbox.
 

cos

Registered User.
Local time
Today, 07:42
Joined
Jul 13, 2012
Messages
81
haha.. its working now!! thx a lot Trevor! and Pr2!
 

Trevor G

Registered User.
Local time
Today, 07:42
Joined
Oct 1, 2009
Messages
2,341
Pleased to read you have a working solution and thanks for letting us know.
 

cos

Registered User.
Local time
Today, 07:42
Joined
Jul 13, 2012
Messages
81
however.. quick question.. how can i filter a subform from this value now? :S
 

Users who are viewing this thread

Top Bottom