By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Can DLookup be used on a listbox?

P: 16
Hi,

I'm trying to get a value from the row of a listbox that is selected by the user.

Is it possible to use the DLookup on a list box something like this

DLookup("[jobID]", "lstEngJobList", "lstEngJobList = selected")

or is there another function I should be looking at using.
Jan 8 '07 #1
Share this Question
Share on Google+
4 Replies


NeoPa
Expert Mod 15k+
P: 31,186
DLookup won't work.
There are arrays associated with the ListBox item that give you access to all items and a way to access the slected line too.
See if you can find them and post back if not. No time to look atm.
Jan 9 '07 #2

ADezii
Expert 5K+
P: 8,597
Hi,

I'm trying to get a value from the row of a listbox that is selected by the user.

Is it possible to use the DLookup on a list box something like this

DLookup("[jobID]", "lstEngJobList", "lstEngJobList = selected")

or is there another function I should be looking at using.
I think NeoPa is referring to the ItemsSelected collection. This hidden collection can be used to access data in the selected rows of a multiselect List Box control. NeoPa, please correct me if I am wrong. To return "Bound Column" values from selected Rows in a List Box name lstTest:
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2. Set ctl = Me![lstTest]
  3.  
  4. For Each varItm In ctl.ItemsSelected
  5.   Debug.Print ctl.ItemData(varItm)
  6. Next varItm
Jan 9 '07 #3

NeoPa
Expert Mod 15k+
P: 31,186
Apologies for such a large post, but there are many ways of accessing this data depending on your needs.
I'm not sure how well that will work ADezii - I can't say for sure as there are many ways to skin cats & I'm no expert here.
The main way to access the data is .ItemData() (as you have) or .Column() which can be more flexible where required.
Look under Help for Selected & ItemsSelected too if you need to worry about milti-selects.
It doesn't seem to mention in the help, but the .Column collection returns the main selected column if no row specified
ItemData Property


The ItemData property returns the data in the bound column for the specified row in a combo box or list box.

Syntax

control.ItemData(rowindex)

The ItemData property has the following arguments.

Argument Description
control A Control object that represents a combo box or list box.
rowindex The row in the combo box or list box containing the data you want to return. Rows in combo and list boxes are indexed starting with zero. For example, to return the item in the sixth row of a combo box, you'd specify 5 for the rowindex argument.
Column Property


You can use the Column property to refer to a specific column, or column and row combination, in a multiple-column combo box or list box. Use 0 to refer to the first column, 1 to refer to the second column, and so on. Use 0 to refer to the first row, 1 to refer to the second row, and so on. For example, in a list box containing a column of customer IDs and a column of customer names, you could refer to the customer name in the second column and fifth row as:

Forms!Contacts!Customers.Column(1, 4)

Setting

control.Column(column, row)

The Column property uses the following settings.

Setting Description
control A Control object that represents the active combo box or list box control.
column An integer that can range from 0 to the setting of the ColumnCount property minus one.
row Optional. An integer that can range from 0 to the setting of the ListCount property minus 1.


This property setting is only available by using a macro or Visual Basic. This property setting isn't available in Design view and is read-only in other views.
Jan 9 '07 #4

P: 16
Thanks guys I haven't had chance to give your suggestions a go yet but sounds like you've pointed me in the right direction, seen as I was way off.
Jan 9 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.