Microsoft Access Subform Search Combobox - ms-access

I am creating a spare part management database in Microsoft Access. I have three tables which are ItemTable, EntryTable and TechnicianTable.
ItemTable has PrimaryKey = ItemID and the value is ItemName.
EntryTable has PrimaryKey = EntryID and ForeignKey of ItemID with lookupwizard.
TechnicianTable has PrimaryKey = TechnicianID and the value is Technician ID.
I need to calculate the stock quantity of each items based on its usage or entries in the EntryTable.
Thus, I have created a Item Stock query that calculates the entries of each item based on "In" or "Out" to calculate the total and group by ItemName. Thus the StockQty field as and expression of Sum(IIf([StatusEntry]='In',1,-1)*[quantity]) AS StockQty.
Now, I want to create a search combobox form based on the Item Stock query to filter the ItemName.
I have created a form with subform. The subform linked to the Item Stock query and the main form has the combobox. In the combobox i have linked the row source to ItemName from ItemTable.
Next I wrote a vba code based on youtube tutorial from here: Access: How to Create Search Form Using Combo box Part 1
When i filter the combobox, the subform is updated which is good but the StockQty column becomes #Name? which i guess is name error and could not find the reference. Is there any solution for this?

To those who are interested, I have solved the problem by following the tutorial in this link!
How To Create A Keyword Search in Access 2013

Related

MS Access: Add Const Value to Table from Different Table

I am building a simple invoice form in MS Access and have two tables that I am trying to link data across. One is a product table, which includes the price field. However, because the price can change at any point, I want to store the price at the time of sale in my line_item table as a constant, unchanging value.
Furthermore, I want to be able to lock both of the values in the invoice form so neither is able to be changed. Because of this, I don't want my sale_price entry in the line_item table to be manually entered. I want it to pull from the product table's price entry.
However, I have yet to find any documentation to help me achieve this exact result.
Can anyone help me out?
This is a common requirement.
Set textbox properties Enabled No and Locked Yes and TabStop No.
To retrieve the price it can be included as a column of combobox where product is selected.
Save the price into record with code behind the combobox AfterUpdate event. It can be done with a macro but I use VBA, ex:
Me!sale_price = Me.cbxProduct.Column(x) - for x reference the column index with the price, index begins with 0.

MS ACCESS 2007 - Selecting Value from Combobox in Subform creates a duplicate value

I am creating a sales database for a small charity in MS ACCESS which should allow a salesperson to enter a Sale and then pull reports etc.. The entry form for the sale (testsales) should create an entry in the sales table. This table has a foreign key for the agency table which in turn stores all the referral agencies we work with.
I have put the combobox for the agency name selection in a subform.
Unfortunately each time I save a sale with a value in the combobox selected, the dublicate value is added to the agency table.
Thanks in advance
Database relations
Salesentry form with subform
If there is anything I should add please let me know.
In your case you can use only combobox or listbox with source of rows from query instead of using subform.
You will have to query AgencyID and AgencyName, make the Bound column AgencyID (1 if you query AgencyID first), but set the width of AgencyID in combobox/listbox to 0 to not show it for users.

Multi-value field to create multiple records?

I have a table connecting three tables, one each for staff, items and programmes:
Staff 1-1 Programme (Each staff member can only be assigned to one programme at any given time)
Staff 1-many Items (Each staff member may request for more than one inventory item)
I create a form for this table, on which I create a combo box to allow the user to select multiple items.
How can I make it such that if for instance the user enters his/her staff ID and his/her programme code and checks off three items, then three records are saved in the table (instead of one record but with multiple values for that field)?
The short answer is you cannot use a multivalue field to created a new record for each checked combo box item unless you want to get into really complex VB Scripting. However, you can do a printout of multivalue fields by creating and running a SQL statement, which does actually present the information exactly how your describing/requesting.
You can set the Row Source for a textbox or combobox on a form by going into the forms Design View and then click on the field text entry area then under Property Sheet > Data > set a SQL Statement to equal different tables to acquire the values you are referencing and then set the Control Source (above Row Source) to the output fieldname/table where you want to store that information.
SELECT tblName.FieldName1.Value AS FieldName, tblName.FieldName2, tblName.FieldName3 FROM tblName;
tblName.FieldName.Value AS something that's not x.Value because x.Value is the individual entries for each multivalued combo box entry for the entire table where this information is "~stored".
If you run the SQL Query above (obviously change to what your actual tables and fieldnames are) then you will see a temporary table (a view) with all the individual values of the multivalues like a printout.
OR
CREATE TABLES: Where I mention references do the steps above but remember you may need to set a condition using WHERE something = something AND OR something.
Staff Programme Table: [UniqueRowID], [StaffNum], [Name], [ProgrammeName], etcetera
The ProgrammeName column references the ProgrammeName in Programme Lookup table. You need to set the fieldname "Display Control" under "Lookup" to combobox then set Row Source to SQL statement like previous mentioned so it knows where to get the values for the programme name.
Programme Lookup Table: [UniqueRowID], [ProgrammeName], etcetera
This contains all values that exist. Easy to update and maintain.
Staff Items Table: [UniqueRowID], [ItemName], etcetera
The ItemName column references the ItemName in Inventory Lookup table. You need to set the fieldname "Display Control" under "Lookup" to combobox then set Row Source to SQL statement like previous mentioned so it knows where to get the values for the inventory item.
Inventory Lookup Table: [UniqueRowID], [ItemName], etcetera
This contains all values that exist. Easy to update and maintain
OR
Alternatively, create another table that contains the values you want. Then create a SQL statement:
INSERT INTO newTableName(newfield1, newfield2, newfield3, etc)
SELECT sourcetblName.sourceFieldName1.Value AS FieldName, sourcetblName.sourceFieldName2, sourcetblName.sourceFieldName3 FROM SourcetblName;

Access 2010 - display related record in a form

I have 2 related tables.
Invoice (fields: number, buyer, supplier, etc.)
Company - all buyers and suppliers (fields: name,etc.)
Buyer ans supplier fields on invoice are referencing same field (company_id from company table)
On invoice form, I choose supplier ID from dropdown list and also buyer ID from dropdown list.
Task: To make the form little bit readable, I would like to automatically display a name of company after selecting company id in both fields.
What I did:
I manually dragged the company name field to the form and wizard asked me which field I would like it to connect to (byuer or supplier), so I got 1 field working. How to create another field that shows company name? If I drag another instance of company name, wizard does not show so I can set it up and I can not find anywhere setting for that. Thank you for help.
I think the best way is the following:
Create a lookup query: Create a new query similar to this “SELECT CompanyId, CompanyName FROM t_Companies ORDER BY CompanyName;” and save it as “ql_Companies”
Edit your Invoice table. For both your fields Buyer and Supplier do the following: Click on the field and select Lookup in the filed properties. Set the following properties: Change Display Control = Combo Box, Row Source = ql_Companies, Column Count = 2, Column Width = 0;5 and save the table.
Now when you create a new form based on your Invoice table the field will be automatically shown as a combobox.
You can also do all this manually on an existing form but then the combo box will only show on this one form. If you prepare the underlying table with lookup queries then this will work in all queries and forms automatically without additional work.

Filtering a Listbox based on Combobox selection

I have two tables: Person and Shift
Person has as lookup field which is a one to many relationship with Shift.
I would like to create a form in which a listbox displaying records from Person is filtered based on the selection of a combobox containing the records from Shift.
in other words, i want to select "days" (value 1) in the combobox, and have only the records from Person that have value 1 in their Shift field displayed in the listbox?
the equivalent sql would be something like:
SELECT * FROM Person WHERE Person.Shift = (the value of the combobox here)
Also, if possible, i would like to do this with little to no VBA as the person i'm passing this off to has no VBA experience and can't be expected to fix bugs in the VBA code.
All you have to do is use the query builder in access and set the criteria to the value of the first combo box
[Forms]![frmMy_form]![cboFirst_combo_box]
Then in the after update event of the first combo box just put
Me.Second_combo_box.Requery