Adding an order for a customer selected from a list view in Access

末鹿安然 提交于 2019-12-25 05:14:41

问题


I followed this great guide to help me add a search feature to my Access database:

http://www.techrepublic.com/blog/howdoi/how-do-i-populate-an-access-list-control-with-the-results-of-a-dynamic-search/108

At the end it says:

"If you’re building a quote or order, use the list control’s Click or Double Click event to copy record(s) to a temporary table. It’s easy to implement using a fixed query for each search task."

I have managed to display all search results in a list box and I would like to be able to click on a customer to highlight them, and then press a button to add an order to the selected customer. I've been thinking how I could do it and I really can't get my head around it.

Any help would be appreciated.


回答1:


It depends on how you build your database. My guess is that one easy way would be:

  • Create a table with customers;
  • Create an "Order" table with orders where you link the customers through a foreign key
  • You load the customers in a listbox. While making the name visible, it is actually the ID that you retrieve when clicking the listbox. You can configure this via the wizard in the design view of a table. You can make other forms appear by events on the listbox (eg. on click).
  • If you managed to retrieve the ID of the customer, and you have the data related to the order (data that can easily be extracted from form objects and loaded into variables ) what you need is an insert statement and insert the values in the "Order" tabel (including the customer ID, which is linked through the foreign key).
  • This way all order records are linked to the customer and can be queried later.

Due to my limited knowledge on your other requests, I cannot help you any further on the rest of your database design. I hope that my reply could help you and that I understood your question correctly.




回答2:


You can access info from a listbox via:

List.Value

Or if it is not the first column then:

List.Column(0,0)

0 being the column and row references.

You may also consider using a listview over a listbox and then you can access the relevant parts of a listview control with the following code:

ListView.SelectedItem

Or if it is not the first column then:

ListView.SelectedItem.SubItems(3)

3 being the column reference



来源:https://stackoverflow.com/questions/11207439/adding-an-order-for-a-customer-selected-from-a-list-view-in-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!