Solved

Listbox bound to Data Control - how do I get 2 fields?

Posted on 2004-10-19
4
155 Views
Last Modified: 2010-08-05

Greetings,

I have a listbox that binds to a data control which sources it's data from a table called RoadMap in an access database. As a result I currently get a list of "names" in the list when the program is run. What I would like to do is get the "name_id" (which is part of the same row in the database: name_id, name, third_field, and so on...) from the row/entry in the listbox that the user ultimately selects and populate a variable that will hold the selected "name_id".

The problem I am running into is that the listbox DataField property will only allow me to specify a single field to display in the listbox, so does that mean that is the only field available in the list? or is the data for the entire row in the table available? if it is, how do I get the "name_id" from the selected row? maybe I should be using some other approach?

Thanks Ahead,

Dave G.
 
0
Comment
Question by:adgarcia13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 12349574
Hi,
  You can try for List view.  This has much better control and you can view as many columns you desire.

0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12350330
0
 
LVL 10

Expert Comment

by:anv
ID: 12354912
hi  adgarcia13

what u can do is...if name_Id fiedl (as is supposed to be) is an integer then in that case..

when u add name's into the listbox...give the index to that name as the name_id value..

which will make ur work easier and also searching etc. will be done easily..


for that do following..

do while not rs.EOF  'where rs is the recordset

  List1.AddItem rs!Name, rs!name_Id  
  rs.movenext
loop


try this if it doesnot work for u then go for a  bit cmplicated method ListView..

or another approach could be to add 2 listboxes..
one of which will store name_id and one its corresponding name for both the listindex would be the same  in the 2 separate listboxes..

but as far as i know...the first method that i shown above...is much feasible and easy-to-use..

0
 
LVL 3

Accepted Solution

by:
Noel_Castillo earned 500 total points
ID: 12355227
If you are using DAO data control then you can use dbgrid control. It can have all or selected field that you want. You can also hide columns but still get their values anytime. The good thing about this is that you can edit its apearance like visible columns and column size even at design time.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
using Access 8 84
How to hault or freeze parent form when a 2d form is open in vb6 3 43
Can we place a tooltip on the actual vb6 form 5 51
Problem to With line 4 75
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 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