Solved

Getting a data value from a list box in Access

Posted on 2007-04-04
7
214 Views
Last Modified: 2010-04-23
I have a list box that's based on a query.  When the user selects an item from the list box, how to I obtain the value of the item selected.  Specifically, the first item in the list box contains the primary key of a table.  When the user selects the item in the list box, I want to assign the row's PK to a variable.  Any suggestions are appreciated!  Thanks!
0
Comment
Question by:christopher_perry
  • 4
  • 2
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 18853563
Assuming the PK is in the first column:

YourVariable = me.lstYourListbox.column(0)

0
 
LVL 61

Expert Comment

by:mbizup
ID: 18853572
(add that code to the double-click event of the listbox, or to another event)
0
 
LVL 13

Expert Comment

by:adraughn
ID: 18853574
You should have the Bound Column (in properties) of the list box set to 1, if the PK is the first item. You can then assign it to a variable by using something like:

i = me.lstMyLstBox.value

adria
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:christopher_perry
ID: 18853723
mbizup - Worked great.  Thank you.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 18853735
Glad to help :)
0
 

Author Comment

by:christopher_perry
ID: 18853756
mbizup - Worked great.  Thank you.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 18853767
Lol!  You're welcome :-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now