Tables: Buy_Header and Buy_Detail.
- Buy_Header: info. of each buy (buy_id(PK, auto number), date, shop, bought_by, ...)
- Buy_Detail: info. of each item from each buy (buy_detail_id( PK, auto number), buy_id, item_name, price, quantity,...)
Target:
- Make a main-form of table [Buy_Header] with sub-form of table [Buy_Detail] to insert/update records for both tables. Each form of each [Buy_Header] and the sub-form can have many records of [Buy_Detail].
- When update, you can add more records to [Buy_Detail] through sub-form
Problem:
- I can make a main-form that link directly to table/query [Buy_Header] with sub-form link to table/query [Buy_Detail] to insert/update. However, although it is easy, the drawback is that I cannot cancel the process. Right after I input value to the main-form fields and click on any field of sub-form, Access will automatically insert/update data of the main-form to DB, even if I later clear all the field (Undo method is kind of useless here). Therefore, I intent to use VBA for insert/update instead.
- However, even though I can insert/update the info. of the form, I have a problem with the sub-form data.
1. I don't know how to get the [buy_id] field from the main-form to put into the data of sub-form.
2. I cannot distinguish each row of the sub-form. I use [datasheet] type for sub-form and naming each field of it. However, when I want to get the value from any field, with VBA, I can only get the value of the field from top row.
I am a totally Access/VBA newbie (but have a good knowledge of coding). Any idea will be appreciated. Thank you.
- Buy_Header: info. of each buy (buy_id(PK, auto number), date, shop, bought_by, ...)
- Buy_Detail: info. of each item from each buy (buy_detail_id( PK, auto number), buy_id, item_name, price, quantity,...)
Target:
- Make a main-form of table [Buy_Header] with sub-form of table [Buy_Detail] to insert/update records for both tables. Each form of each [Buy_Header] and the sub-form can have many records of [Buy_Detail].
- When update, you can add more records to [Buy_Detail] through sub-form
Problem:
- I can make a main-form that link directly to table/query [Buy_Header] with sub-form link to table/query [Buy_Detail] to insert/update. However, although it is easy, the drawback is that I cannot cancel the process. Right after I input value to the main-form fields and click on any field of sub-form, Access will automatically insert/update data of the main-form to DB, even if I later clear all the field (Undo method is kind of useless here). Therefore, I intent to use VBA for insert/update instead.
- However, even though I can insert/update the info. of the form, I have a problem with the sub-form data.
1. I don't know how to get the [buy_id] field from the main-form to put into the data of sub-form.
2. I cannot distinguish each row of the sub-form. I use [datasheet] type for sub-form and naming each field of it. However, when I want to get the value from any field, with VBA, I can only get the value of the field from top row.
I am a totally Access/VBA newbie (but have a good knowledge of coding). Any idea will be appreciated. Thank you.
Comment