help me: itemdata(4)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the ORDERFORM opened and its underlying table is ORDERTABLE. ORDERTABLE has a primary key named ORDER, a currency field named PRICE, and a number field named SKU_ID

The PRODUCT table key field is SKU_ID. There is a one to many relationship between PRODUCT/SKU_ID and ORDERFORM/SKU_ID.
PRODUCT also has a field named PRICE. I don't envision that SKU_ID is a real world entity that will be utilized as gospel, so I want to store the price that the order was sold in the ORDERTABLE as well as the PRODUCT TABLE, because if the PRODUCT TABLE GOES unpopulated, then the user can just type a price into the textbox of ORDERFORM. In other words, the PRICE could be obtained from PRODUCTTABLE or just manually entered

ORDERFORM has a listbox named LISTPRODUCTDATA which gets its data from PRODUCT. If the user clicks a different record in the list box LISTPRODUCTDATA , the value displayed in the text box whose source is SKU_ID(ORDERFORM) changes immediately, I suppose because there is a relationship between the tables and SKU_ID is a primary key in PRODUCT. The value stored in the table ORDERTABLE(SKU_ID) automatically changes to the same value in PRODUCT(SKU_ID)

However, the list box also displays the non key field called PRICE. ORDERFORM has a textbox for it's PRICE, as I said already. I want the value displayed in
the ORDERFORM textbox "PRICE" to change automatically if the user clicks a different product in LISTPRODUCTDATA and be set to the non key value of PRICE in the PRODUCTTABLE

I tried using

Private Sub Listproductdata_Click(
setvalu
End Su
sub setvalu
forms!ORDERFORM!price = 9
En

and the price textbox for ORDERFORM(price) does change to 99 but only after I click on that textbox...not automatically
If I replace 99 with forms!ORDERFORM!listproductdata.itemdata(4) nothing changes

I tried DIRTY() and it didn't work

I obviously don't have a grasp of what's really going on

What do I do and what is really happening...How is it really working?
 
What is displayed in the dropdown part of the list box
'listProductData' is derived from its RowSource property.
It may be a listing of the table or it may be a query or a
SQL statement. I am going to assume that it is a SQL
statement like SELECT sku_id, price FROM Product.

To fill the text boxes when an item is selected from the
list, code similar to the following needs to be placed in
the listbox's AfterUpdate eventhandler

{skuIdTextBox} = listProductData
{priceTextBox} = listProductData.Column(1)

You will need to replace {skuIdTextBox} and {priceTextBox}
including {} with your own text box names.
This will place the value of listproductData (i.e the
skuId) and the cotents of the second column (columns are
counted in a list box from 0) into the two text boxes.

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
I have the ORDERFORM opened and its underlying table is
ORDERTABLE. ORDERTABLE has a primary key named ORDER, a
currency field named PRICE, and a number field named SKU_ID.
The PRODUCT table key field is SKU_ID. There is a one to
many relationship between PRODUCT/SKU_ID and ORDERFORM/SKU_ID.
PRODUCT also has a field named PRICE. I don't envision
that SKU_ID is a real world entity that will be utilized as
gospel, so I want to store the price that the order was
sold in the ORDERTABLE as well as the PRODUCT TABLE,
because if the PRODUCT TABLE GOES unpopulated, then the
user can just type a price into the textbox of ORDERFORM.
In other words, the PRICE could be obtained from
PRODUCTTABLE or just manually entered.
ORDERFORM has a listbox named LISTPRODUCTDATA which gets
its data from PRODUCT. If the user clicks a different
record in the list box LISTPRODUCTDATA , the value
displayed in the text box whose source is SKU_ID(ORDERFORM)
changes immediately, I suppose because there is a
relationship between the tables and SKU_ID is a primary key
in PRODUCT. The value stored in the table
ORDERTABLE(SKU_ID) automatically changes to the same value
in PRODUCT(SKU_ID).
However, the list box also displays the non key field
called PRICE. ORDERFORM has a textbox for it's PRICE, as I
said already. I want the value displayed in
the ORDERFORM textbox "PRICE" to change automatically if
the user clicks a different product in LISTPRODUCTDATA and
be set to the non key value of PRICE in the PRODUCTTABLE.
I tried using

Private Sub Listproductdata_Click()
setvalue
End Sub
sub setvalue
forms!ORDERFORM!price = 99
End

and the price textbox for ORDERFORM(price) does change to
99 but only after I click on that textbox...not automatically.
If I replace 99 with
forms!ORDERFORM!listproductdata.itemdata(4) nothing changes .
 
Well that worked. Thanks.

But I don't understand:

1) textboxname = listbox.column(x)
why does one place the value into the textbox
instead of directly into the table's field? I was trying
fieldname = listboxvalue

2) when do you use itemdata(x)?
tablefield = listbox.itemdata(x)


3) why don't I have to specify
forms!ORDER!textboxname = forms!ORDER!listboxname.column(x)
 
-----Original Message-----
Well that worked. Thanks.

But I don't understand:

1) textboxname = listbox.column(x)
why does one place the value into the textbox
instead of directly into the table's field? I was trying
fieldname = listboxvalue

You have chosen to enter data into the table via a form
and, as such, the data has to be entered via controls on
the form. The form's RecordSource dictates which table the
data is destined for and the control dictates which column.
2) when do you use itemdata(x)?
tablefield = listbox.itemdata(x)

This notation is used to access the data on row x, column 0
of the list box.
3) why don't I have to specify
forms!ORDER!textboxname = forms!ORDER!listboxname.column(x)
That is a valid expression but is cumbersome to keep typing
(or copying and pasting) forms!ORDER!. When you are coding
within the actual form, you can use the Me keyword so
Me.textboxname = Me.listboxname.column(x) is a valid
expression from anywhere within the form called ORDER.
Some of us are too lazy to even type Me. so we shorten it
to textboxname = listboxname.column(x)
 
Back
Top