neeko
neeko

Reputation: 2000

Get value from listbox and copy to control source of unbound textbox

I have a listbox, I want to get the value onclick and copy it to the control source of a listbox in microsoft access.

SearchResults is the name of the listbox

BookTitle is the name of the textbox

I have tried this code but it doesn't seem to work:

Private Sub SearchResults_OnClick()

BookTitle.ControlSource = Forms!Edit!SearchResults.Column(2)

End Sub

Any help is much appreciated thankyou!

Upvotes: 0

Views: 3848

Answers (1)

Fionnuala
Fionnuala

Reputation: 91356

Why do you wish to copy to the control source? Is it the name of a field? If not, just set the value:

Private Sub SearchResults_OnClick()

    Me.BookTitle = Me.SearchResults.Column(2)

End Sub

Do not forget that columns are numbered from zero.

Edit re comments

Very roughly.

Listbox:

SELECT ID, Title FROM tbl_Books WHERE Title LIKE ...

A little code:

Private Sub SearchResults_OnClick()
    'Save
    Me.Dirty=False
    'Find
    Me.Recordset.FindFirst "ID=" & Me.SearchResults
End Sub

Add suitable control sources to any textboxes so you can edit the data in the underlying table. You can hide the textboxes if you wish.

Upvotes: 2

Related Questions