![]() | ![]() |
|
Welcome to the HEXUS.community discussion forums forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and other features. By joining our free community you will have access to post topics, respond to polls and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! |
| |||||||
| Software and web development Databases, graphics, programming, scripting and web development. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Registered+ Join Date: Feb 2009
Posts: 52
Thanks: 1
Thanked 2 Times in 2 Posts
| Getting values from a VBA Listbox Hi guys, In an Access 2007 database, I have a form with a ListBox that grabs the values from one of my tables. I want, when I click on a ListBox item, the value I have selected in the list to appear in a TextBox. I can't seem to find the right code to do. I've tried many combinations, such as something like the following: Code: txtS.Value = lstS.ItemData(lstS.ItemsSelected.Item(0)) Thanks for your help, Leggie |
| | |
| | #2 (permalink) |
| Member Join Date: May 2009 Location: Norfolk
Posts: 144
Thanks: 2
Thanked 8 Times in 8 Posts
| Re: Getting values from a VBA Listbox Sorry, just tried finding the answer for you. Then I realised/remembered how much I HATE Access 2007. I'm going out instead. I had ended up with something similar to what you had posted, but my event handler appeared to be the wrong one becuase I was getting an error becuase the list had no items selected! If you are still stuck tomorrow then I'll sort the code out to do it in Access 2 instead. (Access 2 is the version of Access that I used during the Access developer stage of my programming career.) |
| | |
| | #3 (permalink) |
| Registered+ Join Date: Feb 2009
Posts: 52
Thanks: 1
Thanked 2 Times in 2 Posts
| Re: Getting values from a VBA Listbox I've had no more luck, I'm afraid, so any help would be gratefully received, thanks. I'm also somewhat glad to see that it isn't just me that has trouble with Access! Thanks, Leggie |
| | |
| | #4 (permalink) |
| Large Member Join Date: Apr 2004
Posts: 3,368
Thanks: 25
Thanked 27 Times in 22 Posts
| Re: Getting values from a VBA Listbox I've no idea, but an educated guess would be: Code: txtS.Value = lstS.ItemsSelected.Item(0).Value To err is human. To really foul things up ... you need a computer. |
| | |
| | #5 (permalink) |
| Three As fanboy... Join Date: Jan 2009 Location: Manchester
Posts: 1,600
Thanks: 60
Thanked 119 Times in 117 Posts
| Re: Getting values from a VBA Listbox Good lord the Access 2007 help is appalling, isn't it. I've never been able to find anything in office help since 2002... Anyway, the code you are looking for is Code: txtS.Value = lstS.Value ) you'd needCode: txtS.Value = lstS.List(lstS.ListIndex, columnindex) Code: Dim result as String, i as Integer
For i = 0 to lstS.ListCount - 1
If lstS.Selected(i) result = result & lstS.List(i, columnindex) & ", "
Next i
txtS.Value = result
// // TODO: Add witty signature here // |
| | |
![]() |
| Breadcrumb | ||||||
| ||||||
| Tags |
| vba |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CS21A550 default deflection values needed. | tusharfrompune | Help - technical & advisory | 0 | 23-07-2009 05:19 PM |
| Any good VBA books? | stroberaver | Software and web development | 8 | 21-07-2009 08:35 AM |
| Ram CAS latency values help please! | mathewdbarlow | HEXUS.hardware | 2 | 26-01-2007 01:25 PM |
| British Core Values? | BEANFro Elite | General discussion | 48 | 17-05-2006 11:35 AM |
| multi boot options | robbiehall | Operating systems & applications | 4 | 27-10-2003 07:55 PM |