A seemingly simple question that has me stumped.
I have a table [Inventory] with the following fields: [Category], [ItemName], [Price].
ex: "Plumbing", "ACME Showerhead", $43
I have a table [Categories] with the fields [Category], [SubCategory]
ex. "Plumbing", "Hardware" or
ex. "Flooring", "Wood"
I wish to have a form (ideally a standard grid) that allows me to enter new Inventory Records.
On this form would be the fields Inventory.Category, Categories.SubCategory, ItemName, Price.
When navigating to the field Inventory.Category, a drop down should allow me to select from Unique Categories.Category values. Once selected, the Subcategory field should allow me to select from valid subcategories of that Categories.Category. For example, if I chose "Plumbing" in the category field, I would only be presented with teh subcategory "Hardware" and not the subcategory "Wood".
I would also like the ability to add new Category Records while in this form, so I am not limited to whats in the dropdown. So for example, when adding a record to Inventory, if I want to create a new Category/SubCategory pair of say, "Plumbing", "Pipes", I should be able to do that without having to switch to another form/table or whatever.
Related
I have created a simple inventory management Access DB which in its basic functionality works perfectly.I would like to start to make some polish here and there and I've found the next issue.
I do have a main form for inventory transactions. It has a Header section (with a table of transactions header as a recordsource) and a details section (datasheet type subform into the main form; which means a multiple records form where I can add or remove multiple lines for each header transaction and it is linked to the main form, that works OK).
In this detail/lines subform I have the fields: Category (combobox), Item (combobox) and Quantity (category and item fields are linked to "master categories" table and "master items" table).
I do want to add the following behavior:
When I select a category on category combobox field, the item field updates its selection to show only the items in the selected category.
I can do this easily on a single record form with this code:
Private Sub Category_AfterUpdate()
Me.Item.Requery
End Sub
On the Item field datasource I do have a simple query:
SELECT ID,DESC FROM ARTICLES WHERE ARTICLES.CATEGORY = [FORMS]![SUBFORM].[CATEGORY]
This works flawlessly with a single record form.
However as this is a multiple lines/records form when I select a category on a line, it updates the "Item" selection field for ALL the lines/records, even changing values depending on the selected category.
Is there a way to update controls/fields in an independent way for each record on a datasheet form? Let's say something like:
Private Sub Category_AfterUpdate()
Me.Item(current record).Requery
End Sub
I'm thinking on adding an index to the combobox article field and update only the field on that index but I don't know how to proceed or if it's possible to do that.
Any ideas or workaround to do this?
I have a couple of list boxes on a form that I've created. One of the listboxes has a bunch of supplier names (lst_SupplierName). Upon selecting a supplier name it then auto-populates all Part Numbers under that supplier in another list box (lst_PartNumber).
I would like to take it a step further. So The Part Number listbox is now populating I would like to select a part number and based on that part number be able to create a query that lists all required attributes associated with that part number from the table it's contained in.
Make 2 lists, first one that queries supplier table, second one that queries part table that will use value of first list to query parts only for that supplier. Here is sample tables I created:
And form:
The first list row source is:
SELECT [tblSuplier].[SupID], [tblSuplier].[SupName] FROM tblSuplier ORDER BY [SupName];
Second list row source is:
SELECT tblPart.PartID, tblPart.SupID, tblPart.PartName, tblPart.PartDescr FROM tblPart WHERE (((tblPart.SupID)=[Forms]![frmMain]![lstSup]));
To make second list update, when you select something in first list, you need to add 'after update' event on first list:
Private Sub lstSup_AfterUpdate()
lstPart.Requery
End Sub
Now, you can use after update event to populate different fields on form from parts list the same way - by simply placing value into fields, like txtDescription = lstPart.column(2=3) .
If you have any questions, please let me know.
I have a couple of tables in my database.
workout_moves - ID, workout Type, Exercise, Reps
session_moves - ID, Exercise(from workout_moves table), Weight, Notes
I have created a form called workout session which has created a subform for the session_moves table.
The session_moves subform looks like this :
This is fine -but when I select my exercise from the list, I want it to autopopulate the associated Reps value from the workout_moves table rather than forcing me to pick from the list, which is not quite what I would like.
As you can see in the workout_moves table, each exercise is matched to a reps column so this should be pretty easy:
I just cannot work out what the "Row Source" should be for the Reps column in this form in order to auto pull in the data associated with the selection in the Exercise column. Please help.
Set the control source to
=Dlookup("Reps";"workout_moves";"[workout Type] = '" & Nz(cboExercise;"") & "'")
in the Reps control. cboExercise is the controlname of the exercise combobox.
Think about changing foreignkey in table session_moves from Exercises to ID (use primarykeys as foreignkeys).
Short form of the question:
How can I set a filter for the form which is used by the "List Items Edit Form" property of a ComboBox?
Long description of the environment:
In my database, there is a growing number of structurally similar values which describe something. I collated all of these in one table named ComboTexts, and added a second table ComboTextTypes to customize the field names on the user side. Example:
ComboTexts table:
ID s1 s2 s3 TypeID
1 1 First Floor Ground Floor 2
2 2 Second Floor Null 2
3 AOX DIN 1485 determination of organic components 3
ComboTextTypes table:
ID formtitle ch1 ch2 ch3
2 Floor Floor Number Floor Name Alternate Name
3 Process Process name Standard Description
In order to edit entries in ComboTexts, I provide two forms: The form CoreData displays the list of formtitles from ComboTextTypes and an "edit" button. When the user selects a fomtitle and clicks "edit", the form EditComboTexts is called with a filter for TypeID set. EditComboTexts extracts the TypeID from its filter and modifies itself with the information from ComboTextTypes.
So far there exist 14 ComboTextTypes in the database, and that number is growing. I simply didn't want to have 14 or more tables and forms, which basically all do the exact same thing. Instead I just have two tables and forms, although a little more complicated ones.
The above mechanic is all set up and works fine.
Description of the problem:
The users want to be able to modify the 14th ComboTextType from inside the combobox. The detour through CoreData is three clicks too many, they know that ComboBoxes can offer an edit button for their value list, and want to use it at that point.
Access offers the "List Items Edit Form" for this purpose. When I enter the EditComboTexts form there, it's working in principle, but (of course) the filter is wrong.
How can I set a filter for that form?
You can filter the rowsource using SQL and simply change the rowsource value of the combo box
Me.Combo0.RowSource = "SELECT myfield FROM Table2 WHERE Table2.myfilter = 'value' ; "
I'm working on a small little project, at the moment just a test for a larger project, but I've hit a block that I can't find a solution too.
I have a list of items in a table, and they contain information such as the item name and the price. I have another table with sales. I have a form that will allow you to select a item name, however, then I would like the rest of the form to be auto-filled with information from the items table.
I can make a message box appear when the item name field has been changed, however, through my searching, I am unable to find a way to search the items table for the value of the field, then read the price value, then insert the price value into a field in this form.
First table "items":
itemname: text
price: currency
Second Table "sales":
itemname: text
price: currency
date: time/date
I hope I have explained myself well enough, if not, just ask and I will try to clarify.
Have a look at the Northwind datatabase (northwind.mdb) that ships with Access. They have several examples of how to update a form based upon a combobox changing values.
Also, you might want to look at the table design in the Northwind Database as well. Generally speaking, it is a bad idea to use the product name as the key field in both of your tables. What will happen (and it will eventually) is that the product name is going to change for one of the products and you'll have to update all of the tables that reference that product name.
The better design is to use a key field (I'd recommend an AutonumberField) in your products table and then reference the key field in the sales table. This way, if the product name changes you only have to make the change in one location, not many.
Here's a sample table layout to illustrate my point:
Table Items:
ItemID (Autonumber - Primary Key on the table)
ItemName (Text - Name of product)
Price (Currency)
Table: Sales
ItemID (Integer - Foreign Key to Items.ItemID)
Quantity (Integer - # of units ordered)
Price (Currency)
OrderDate (Date/Time)
Most answers here are posting way too much code and all kinds of SQL statements. As such, these answers are creating world poverty.
The most simple approach is to let the wizard build a combo box on your form to select a given item. This combo box will thus based on the items table. The first column of the combo box will be the PK (autonumber ID) of the items table. This combo box will thus be bound to the ItemID column in sales. The wizard will also “hide” the id, but you WANT to include the other columns in this combo box such as price etc. And you likely should have the 2nd column of this combo box the description of the item from the item table. As noted, you ALSO want to include the price column.
Thus, after you select a item, then to have auto matic fill out the price column, use this code:
This code goes in the AFTER update event of the item combo box:
Me.Price = me.ItemComboBox.column(2)
So when you select a item, the price field will to auto filled for you. And note how you only had to write one line of code.
So all of this can be done using built in wizards and one line of code.
Add an event procedure (code builder) to the dropdown box's onchange event. Right click the dropdown in design view and choose properties. then on the event tab in the properties window click in the on change line and click the '...' button.
In the code for this event you'll need to query the DB (using the dropdown box's index or ID field) to pull the items details into a recordset. The query would look somethign like
"SELECT * FROM Items WHERE ItemID = " & dropdownboxname.value
theres plenty of examples of how to do this on the web
Then you can update the various textboxes in the form with the required fields in the recordset. again theres plenty of examples of this on the web
EDIT:in response to comments below
you'll need to do somethign along the lines of...
Dim rsItems AS DAO.Recordset
Set rsItems = CurrentDB.OpenRecordset("SELECT * FROM Items WHERE ItemID = " & dropdownboxname.value)
If not rsItems.EOF Then
textbox1.text = rsItems![fieldname1]
textbox2.text = rsItems![fieldname2]
end if
Set rsItems = nothing
let me know if thats any help ;-)