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

help! pass listbox item to a subform

P: n/a
I have a listbox (of product names) control on my form. I want to pass the
selected item (a product name) to a subform, and the product unitprice
should apear automatically next to the product name in the subform. Is it
possible? How do I do this? Thanks in advance.

Paul from Slovakia
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
If your subform is unbound (the subform is not using a Table or query as
its recordsource) and you have like a textbox control (or some other
control) then you might think about placing those controls on your main
form. The purpose of a subform is to display data from a table or query
in Datasheet View. The reason for this is because if you select
Datasheet View on the main form, you cannot see your other controls. So
you use a subform in Datasheet view, you place that on your main form as
just another control, along with other controls like a textbox, listbox,
etc.

As for getting data from a listbox:

Text1 = List1.Column(0) 'if you have a one column listbox

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd set up the ListBox's RowSource property to return both the product
name and it's price. Hide the Price by setting its column width to
zero. The RowSource SQL would look something like this:

SELECT ProductName, Price FROM Products

The ListBox's ColumnWidths would be something like this:

Column Widths: 1.5";0"

Zero indicates the Price will not show in the ListBox.

I used inches (") - change to whatever metric you normally use.

The following assumes the ListBox is not a multi-select list box (IOW,
only one item can be selected at a time). In the subform controls, pull
the data from the ListBox like this:

ProductName:
The product name is in column zero (1st column in SELECT clause)
ControlSource: =Parent!ListBoxName.Column(0)

Price:
The price is in column 1 (2nd column in SELECT clause)
ControlSource: = Parent!ListBoxName.Column(1)

See the Access Help articles on "Parent" and the Column property of the
List/Combo Box controls.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQUhrVYechKqOuFEgEQJl1wCfeZ+YYg57qs5xkrhcZ+u8X+ pxKJoAn0HY
Q+K0OgrXNsOhU1ms+wTjA1e7
=T/DR
-----END PGP SIGNATURE-----
Paul T. Rong wrote:
I have a listbox (of product names) control on my form. I want to pass the
selected item (a product name) to a subform, and the product unitprice
should apear automatically next to the product name in the subform. Is it
possible? How do I do this? Thanks in advance.


Nov 13 '05 #3

P: n/a
Thank you very much MGFoster.

I tried according to our idea, it works only partly. What I really want is,
when one clicks one row of the listbox, the item, say, product name will be
displayed in the subform in the first line together with its unitprice, when
one clicks another row of the listbox, the other product name comes to the
second line with its unitprice too, and so on.

I thought using INSERT INTO would make it possible. I mean to insert records
from the product table (which is the source of the listbox control) into a
query say called "order_detail_query" which is the source of the subform.
Howerver, as a beginner on sql, it is tough for me to complete my plan. I
understand your idea and appreciate your help very much. I won't give up.

Maybe it is a good topic, everybody is welcome.

Thanks to Rich too,

Paul

----- Original Message -----
From: "MGFoster" <me@privacy.com>
Newsgroups: comp.databases.ms-access
Sent: Wednesday, September 15, 2004 6:18 PM
Subject: Re: help! pass listbox item to a subform

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd set up the ListBox's RowSource property to return both the product
name and it's price. Hide the Price by setting its column width to
zero. The RowSource SQL would look something like this:

SELECT ProductName, Price FROM Products

The ListBox's ColumnWidths would be something like this:

Column Widths: 1.5";0"

Zero indicates the Price will not show in the ListBox.

I used inches (") - change to whatever metric you normally use.

The following assumes the ListBox is not a multi-select list box (IOW,
only one item can be selected at a time). In the subform controls, pull
the data from the ListBox like this:

ProductName:
The product name is in column zero (1st column in SELECT clause)
ControlSource: =Parent!ListBoxName.Column(0)

Price:
The price is in column 1 (2nd column in SELECT clause)
ControlSource: = Parent!ListBoxName.Column(1)

See the Access Help articles on "Parent" and the Column property of the
List/Combo Box controls.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQUhrVYechKqOuFEgEQJl1wCfeZ+YYg57qs5xkrhcZ+u8X+ pxKJoAn0HY
Q+K0OgrXNsOhU1ms+wTjA1e7
=T/DR
-----END PGP SIGNATURE-----
Paul T. Rong wrote:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice
should apear automatically next to the product name in the subform. Is it possible? How do I do this? Thanks in advance.



"MGFoster" <me@privacy.com>
??????:QX***************@newsread1.news.pas.earthl ink.net... -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd set up the ListBox's RowSource property to return both the product
name and it's price. Hide the Price by setting its column width to
zero. The RowSource SQL would look something like this:

SELECT ProductName, Price FROM Products

The ListBox's ColumnWidths would be something like this:

Column Widths: 1.5";0"

Zero indicates the Price will not show in the ListBox.

I used inches (") - change to whatever metric you normally use.

The following assumes the ListBox is not a multi-select list box (IOW,
only one item can be selected at a time). In the subform controls, pull
the data from the ListBox like this:

ProductName:
The product name is in column zero (1st column in SELECT clause)
ControlSource: =Parent!ListBoxName.Column(0)

Price:
The price is in column 1 (2nd column in SELECT clause)
ControlSource: = Parent!ListBoxName.Column(1)

See the Access Help articles on "Parent" and the Column property of the
List/Combo Box controls.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQUhrVYechKqOuFEgEQJl1wCfeZ+YYg57qs5xkrhcZ+u8X+ pxKJoAn0HY
Q+K0OgrXNsOhU1ms+wTjA1e7
=T/DR
-----END PGP SIGNATURE-----
Paul T. Rong wrote:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice
should apear automatically next to the product name in the subform. Is it possible? How do I do this? Thanks in advance.

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.