MS Access Database - Chart Drawing From Lookup Control - ms-access

I am trying to create a pie chart in a MS Access report. The problem is that the field in the table from which I am trying to draw the data is a lookup field, drawing its data from another table. So when the pie chart is rendered, the labels are coming up as the numerical id for the entries rather than the text labels.
The structure is something like this:
Discrepancies Table:
column1 - ID
column2 - Name
column3 - Category - lookup from categories table
Categories Table:
ID
category (name of the category)
In the discrepancies form I have the category field bound to the "category" column (column1), so the text label appears in the table.
However, in the pie chart, which draws from the category field in the Discrepancies table, the label is the numeric ID of the category rather than the name.
How can I get the name to appear as the label rather than the ID?

I figured it out by creating and basing my pie chart on a query, rather than by pointing it a row source.
The query was SELECT DISTINCTROW categories.category, Count(*) AS [Count Of discrepancies]
FROM categories INNER JOIN discrepancies ON categories.[ID] = discrepancies.[category]
GROUP BY categories.category;

Related

MS Access Identical Comboboxes for Autofill

I have two tables:
'tableStudent' - a list of students given an ID number by the table, with following columns:
student_ID
last_name
first_name
and 'tableProject' which gives each project an ID and will be used to store information about the students involved in the project. Students will work in pairs on the project. This table includes the following columns:
project_ID
project_title
student1_ID
student2_ID
The columns student1_ID and student2_ID are combo-boxes that link student_ID to the student names.
I want to create a form that can be used to record students involved in a project. I want to be able to select the student IDs and have the student names autofill on a form.
I can make a form that autofills, but only with one student with this SQL:
SELECT tableProject.project_ID, tableProject.project_title, tableProject.student1_ID, tableStudent.last_name, tableStudent.first_name
FROM tableStudent INNER JOIN tableProject ON (tableStudent.student_ID = tableProject.student2_ID) AND (tableStudent.student_ID = tableProject.student1_ID);
When I add Student 2, I get a duplicate error on the student names. How do I indicate that the two names belong to different students? This is the code I'm generating:
SELECT tableProject.project_ID, tableProject.project_title, tableProject.student1_ID, tableStudent.last_name, tableStudent.first_name, tableProject.student2_ID, tableStudent.last_name, tableStudent.first_name
FROM tableStudent INNER JOIN tableProject ON (tableStudent.student_ID = tableProject.student2_ID) AND (tableStudent.student_ID = tableProject.student1_ID);
Any help appreciated!
Options for displaying related info from lookup table:
Use Access query designer to build form RecordSource. Pull tableStudent into query designer. In your case pull in twice - second instance will get named like tableStudent_1. Join each to one of the student fields. Bind textboxes to both sets of lookup table fields and set them as Locked Yes to prevent edit.
Don't include lookup table in form RecordSource at all. Include all student info in combobox RowSource. Expressions in textboxes refer to combobox columns by index, index begins with 0: =[comboboxName].Column(1)
DLookup() domain aggregate function, however, since your tables have a relationship, this is an inefficient method.
For all options, set textboxes with TabStop No.

MS Access OpenRecordSet of QueryDef not always returning bound column of lookup

Found a number of helpful posts but not it relation to bound columns of lookups.
I have a simple table Tasks with two lookup columns Category and Area. Category is a single column lookup bound to column 1. Area is a dual column lookup bound to column 2.
tblTasks:
ID, Category (Lookup), Area (Lookup), OtherData...
Category (Lookup RowSource) = select Category FROM tblCategory; (Bound Col 1)
Area (Lookup) RowSource = select ID, Area FROM tblArea; (Bound Col 2)
tblCategory:
ID, Category
tblArea
ID, Area
I have a separate query for each which returns the correct expanded lookup values.
Now via VBA...
When I open the recordset of the Category query I get the category of the lookup returned as expected.
When I open the recordset of The Area query I get the ID of the lookup returned instead of the Area.
I get the impression the bound column must be 1 or bust!!!
Otherwise is there a way to force the bound column of the lookup to be honoured by the openrecordset?

Getting values from form as query criteria

I have a library database. There are some kind of data (books, magazines and etc.).
I have a form on base of report of these data. In this example I'm trying to add in combobox just one value - Name of the book. I'm doing it by such a query in row source of the combobox:
SELECT [Forms]![books_list]![name] AS id;
books_list - the name of the form and name is the text box called name.
It returns only the first name of the book in all comboboxes - 123.
I need to show only these name values in different comboboxex, which has reference by the row.
To make it clearer - in first combobox - 123, second - Прошлое, third - May be next time.
As I understand, you want to take the value from the text box name, and use a query to select the same value in the combo box?
SELECT <insert your column name here>
FROM <insert your table name here>
GROUP BY <insert your column name here>
HAVING ((<insert column name here>)=[Forms]![books_list]![name] AS id);

Add Description Column in query from product list table

I'm a beginner to access and I made a database where I currently have two tables:
Product list table that has 3 columns: ProductID, Description, Description2
A scan table where the user will use a barcode scanner and scan the barcode into the table. It only has 2 columns: ID, and Barcode
I have a query where the first column is the raw barcode and the second is a mid function expression(?) where I extract the information such as product code ( I will add different columns, later, extracting weight, pack date, serial) from the barcode.
Currently, I would like for the the third column to show the Description and Description fields from the product list table. In excel I can do a vlookup, and I have been reading up on Dlookup, but I was wondering if there is an easier alternative to Dlookup because I can't get it to work. Thanks in advance!
Let us say that the query to extract product code is:
SELECT Barcode, Mid(Barcode,6,3) As ProductID FROM Barcodes
It is possible that you have an number data type for ProductID in the Products table, in which case you will have to ensure you have a number data type in the query, you can do this like so:
SELECT Barcode, CLng(Mid(Barcode,6,3)) As ProductID FROM Barcodes
You can either add this saved query to the Query Design Window along with you Product table and drag the ProductID field from one table to the other to create a join:
Or you can build a query using SQL view of the Query Design Window:
SELECT q.Barcode, Products.ProductID, Products.Description
FROM (
SELECT Barcode, Mid(Barcode,6,3) As ProductID
FROM Barcodes) As q
INNER JOIN Products
ON q.ProductID = Products.ProductID
Of course with the second option, you will have to get everything right for your set up.

Microsoft Access question

I have a combo box which has 3 pieces of information
COMBO BOX 210: Materials ID, Name of Product, Cost, Description
After I update the combo box the cost figure is stored in another field in the table, so far so good, so in selecting "Apples" the cost "$1" stores.
Now, what I want to is have a different field where the description of the apple (the text) is stored yet I only update the combo box once, in other words after updating the combo box Field 1 stores the price and Field 2 the description of the apple.
I will offer you a different example which I hope is similar to what you're asking.
My form includes a combo named cboNames. This is the query for its row source:
SELECT f.id, f.fname, f.date_added
FROM food_test AS f
ORDER BY f.fname, f.date_added;
In the combo's After Update event I can access the values of those 3 columns in the selected combo row by referring to the Column index. Notice the column index numbering starts with zero.
Private Sub cboNames_AfterUpdate()
Debug.Print Me.cboNames.Column(0)
Debug.Print Me.cboNames.Column(1)
Debug.Print Me.cboNames.Column(2)
End Sub
So if I wanted to put the date_added value into another data control, I could add this to the combo's After Update event.
Me.SomeOtherControl = Me.cboNames.Colummn(2)
However I wouldn't actually store both id and date_added in a row of another table. In my food table, each id is associated with a unique combination of fname and date_added. So I would store only the id, and use a SELECT with a JOIN to the food table to look up the associated fname and date_added values whenever I needed them.