Access 2007 - Building unmatched data query, but need two field categories - ms-access

Is it possible to build an unmatched data query using two tables with a tracking a unique value field and also another value in the row as well (that value will not be unique).
For example I want to track a unique customer code from an invoice on a new table, compared to last month's invoice. The non unique value would be a "product code" of what they purchased.
A customer code could appear multiple times depending on if they have purchased multiple product codes.
Any help is much appreciated.

This should do what you want:
SELECT Invoice.CustomerID
FROM Invoice LEFT JOIN PreviousInvoices
ON (Invoice.Product = PreviousInvoices.Product)
AND (Invoice.CustomerID = PreviousInvoices.CustomerID)
WHERE PreviousInvoices.Product Is Null

Related

How to do a lookup or index/match in Access?

I'm new to access and I'm struggling on how to use lookups since vlookup is not available in Access. I want to get the values that correspond to a certain ID/tagging.
I have 2 tables.
Table A contains values let's say Product Number, Product Type, Price, Remaining Stock #, Product Type+Product Number Tag. Let's say product number is not unique but combining it with its product type, it will be unique so I created that tag.
Table B contains Seller's Name, # of items Sold, Product Number, Product Type, Product Type+Product Number Tag.
Now using Table A and Table B, how can I create a query/table that will allow me to use that "Product Number + Product Type" Tag when I try to get the price of that certain item so that I can get the total revenue of each seller.
I hope you understand what I'm trying to say. What I just want to do is I want to use this "Type+Number" Tag as a reference point in getting data of that respective item when I try to create queries/tables. It's just like an INDEX/MATCH in Excel. But how to do it in Access?
Please tell me if it's unclear.
Thank you!
You need to join your two tables based on the relationship between the Product Number & Product Type fields in both tables.
The two fields in Table A should be marked as the composite Primary Key (select both fields and in the Design ribbon click the Primary Key icon).
In Table B they will be Foreign Keys - a seller could sell those products more than once, so duplicates are allowed here.
You don't need the Product Type+Product Number Tag field.
The SQL for your query would then be:
SELECT *
FROM [Table A] LEFT JOIN [Table B] ON [Table A].[Product Number] = [Table B].[Product Number] AND
[Table A].[Product Type] = [Table B].[Product Type]
This will return all records from Table A and only those records from Table B that match the Primary Key.
Finally.... don't think of an Access table as an Excel spreadsheet. Access is all about the relationship between pieces of data - for a start queries can be expressed in plain English a lot easier.
E.g return all records from table B where seller name is "Dave" and date is between 1st Jan and 31st Jan would be written as:
SELECT *
FROM [Table B]
WHERE [Seller Name]='Dave' AND
[Sale Date] Between #01/01/2018# AND #01/31/2018#
(SQL only deals in US date format).
You can use DlookUp Function.
It can be used on queries as a calculated field, or in code in VBA:
For example, to get the price of a PRoduct, you could use something like:
DlookUp("[Price]";"Table A";"[Product Type+Product Number Tag]='" & Value & "'")
From my point of view, the complex part of DlookUp is the third argument, the WHERE clausule. If you have any experience with SQL, you will have no problem. If you don't, don't worry, just read some info and if you get stuck, come here to SO
You can use DlookUp to get any value of any field, based on a criteria (criteria applied to a unique field, ofc).
And yes, you can use it to get values from tables or from queries. In the link I provided before, it explains how the arguments works.
The most complex part is the criteria part. You must write as if you were typing a WHERE clausule on SQL more info here
About the criteria, always remember this:
If your criteria is a numeric value, then just type [field_criteria]=my_numeric_criteria
If your criteria is a text value, you must use single quotes. For example, [field_criteria]='my_text_criteria'
SQL requires single quotes around text values.
Try it!

MS Access 2010 Issue

Table1 feildes
Product{ID,Product,Quantity(in peices),Cost(per peice)}
table2
Customer{ID, Name, Type(local,sale's man)}
table 3
customer order{ID, date,customer*, product*,quntity,price}
here customer is coming from table 2 named as customer while product is coming from table1 named as products
i just want to show remaining items in order table. any can help me to make this happen?enter image description here
You mean you want to know how much of each product remains after filling orders? This is calculating inventory balance - a common topic. You need a table that records receipt of product, which is apparently your Products table but I think would be better titled ProductReceived. Do an aggregate query on ProductReceived and an aggregate query on Orders then do another query that joins the two and subtracts the latter from the former. Customer table not needed for this. Products table would just be a lookup table for product info - no Quantity or Cost fields as these belong in ProductReceived. Products table should have the selling price you want to charge.
You have misspelled 'piece' in your field names.
Advise no spaces, punctuation, or special characters in field names (underscore is only exception). Better would be Qty_Pieces.

MS Access: Report to contain info from third table

I'm currently working on a database for a company, for them to use when making production orders. A report is to be made consisting of several things, mainly product number, order number etc etc. A part of the report is to be made up of a list of spare parts needed for the production of the item in question. I have a table with an order number and product number, which needs to look in another table to find the necessary spare parts. However, the name, location and stock of those spare parts are in a third table, and I can't seem to find a way to include these things automatically when the product number is known. I'm pretty new to MS Access, so any help will be greatly appreciated. Thanks!
I have a table called Table1, which uses a combobox to automatically fill boxes such as production time, test time etc from a given product number. This data is gathered from the second table StandardTimes, which has as a primary key the product number. Other columns in this table includes production area, standard quantity, average production time, and also includes in several columns, the necessary spare parts needed. In a third table called Inventory, we have the product numbers of the spare parts, their location in storage, and number of items currently in store. I created a report using a query which takes an order number, and creates a report on that order number from Table1. What needs to be included in this report is a list of the spareparts necessary, the location in the storage, and the number of items currently in store.
Revised from new user input
Your question still does not provide actual columns or data. As a result, it's hard to model your needs.
However, based on what I can read, I think that you have are missing some basic design setup items in a relational model.
Assuming that you have 3 tables: Table1 (Orders), StandardTimes (Products) and Inventory (SpareParts)
In English, every order has one or more products. Every product has one or more spare parts. Really you'd want an orders table, and an order details table which has records for each item as part of that order. But I'm answering it on your setup which I believe is flawed.
Orders <-(1:M)-> Products <- (1:M) -> SpareParts
You have an OrderID, a ProductID, and a SparePartID.
A query such as this would join those 3 tables together with that kind of relationship.
SELECT o.OrderNum, o.ProductNum, st.ProductionArea, st.StandardQuality, i.SparePartsNum, i.Location, i.Qty
FROM Orders as o
INNER JOIN StanardTimes as st on o.ProductNum = st.ProductNum
INNER JOIN Inventory as i on i.ProductNum = st.ProductNum
Some sample data would be helpful to help design the queries.
In principal you would need to join the tables together to get the desired result.
You would join the productID on tblOrders to the ProductID on tblProducts. This will net you the name of the product etc.
This would be an INNER join, as every order has a product.
You would then join to tblSpareParts, also using the productID so that you could return the status of the spare parts for that product. This might be a LEFT JOIN instead of an INNER, but it depends on if you maintain a value of 0 for spare parts (e.g. Every product has a corresponding spare parts record), or if you only maintain a spare parts record for items which have spare parts.

How to return invoice numbers - where all associated detail records have a bit field set to 1

SQL novice here.
I'm trying to get a list of invoice numbers. There are two tables - invoices and invoicedetail. The invoicedetail table has a field called scanned (it's a bit field). If it's been scanned, then the bit field is 1.
For each invoice, there are associated records in the invoicedetail, but I only want a list of the invoice numbers where every associated record in invoicedetail's scanned field is 1.
I'd rather do this in a single query if possible.
The records scanned in InvoiceDetail is all records - for any invoice number returned.
Your help is appreciated.
SELECT
InvoiceNumber
FROM
Invoice
INNER JOIN
InvoiceDetail
ON
InvoiceDetail.ID = Invoice.ID
WHERE
InvoiceDetail.ScannedColumn=1
GROUP BY
Invoice.InvoiceNumber
Or...
SELECT
DISTINCT
InvoiceNumber
FROM
Invoice it
INNER JOIN
InvoiceDetail idt
ON idt.ID = it.ID
WHERE
idt.ScannedColumn=1
Just make sure you change the column names to fit your needs. Use your ID from each table for the joins and then use a WHERE to filter the records to just show those which are scanned. Being that you are using a bit field you will simply use WHERE ScannedColumn = 1.

DLookup to return prices

Good afternoon all,
I am in the process of creating a database in which I want to enter a product name and a dose and a price will be returned. I have created two tables (tbllog and tblcosting). The tblcosting contains the products along with all the available doses and the prices they cost. Is there a way of inputting the product and dose onto one form and having a box that returns the price based on these two criteria?
Any advice you could pass on would be very much appreciated.
Select product from a combobox. Make the combobox RowSource multi-column:
SELECT ProductID, ProductName, Dose, Cost FROM tblCosting ORDER BY ProductName;
Have textboxes reference the combobox columns by index to display the associated info. Index begins with 0 so Cost is in column index 3:
=[cbxProduct].Column(3)