Ms Access, How to get auto-value from another table - ms-access

I have 2 tables, customers data and activity. The customers data table has information like customer id, customer name, etc. What I want is when I input the customer ID in activity table, the customer name fill itself automatically, How can i do that? Thank you.

Use a query to link the two tables together by Customer ID. However, if you want to display the name on a form that is bound to the Activity table, you can use a DLookup on a field.
=DLookup("CustomerName","CustomerTable","[CustomerID] = " & me.CustomerID)

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.

Best way to retrieve last records values inserted into database

I'm saving a record into a customer table, and the customer table has an customer number that auto increments. I would like to know what is the best way to get that newly generated customer number directly after it was created? For example, let us say the customer table has 3 columns, ID, Name, Surname. I use the following code:
database.tbCustomer.Insert;
database.tbCustomerName.Value := edtName.Text;
database.tbCustomerSurname.Value := edtSurname.Text;
database.tbCustomer.Post;
So once I have done this, I need to get the ID that was created, as I need to use that as a FK in another table. So the easy way I suppose is to just go to the last record in the customer table, but that gives problems if more then 1 person is creating customers.
database.tbCustomer.Last;
but that approach can lead to the wrong ID being returned if more then 1 customer gets created at the same time. So how would I get the customer ID for the customer that I just created? Using Delphi, and storing the data on mysQL, using FireDAC.
Probably what you are looking for is GetLastAutoGenValue. See the documentation

Access 2013 - How do I link a result, from a query generated table, to a form?

I have 2 tables, CUSTOMER and ORDERS, whose common field is CUST_ID.
In addition to CUST_ID (key field), the CUSTOMER table has fields for customer info - address, phone number, etc. I have a form that displays this information.
In addition to CUST_ID (which us not a key field), the ORDER table has fields for product, quantity and total price for each order a customer makes. A customer could have multiple orders. I created a query that gives me the total cost of all orders of for each customer. What I want to do is link the result of this query to the customer info form, so the total cost, for the appropriate customer, appears with the other customer information as mentioned.
How can I link the result of this query to that form?
Thanks.
You can use DLookup as ControlSource for an unbound textbox:
=DLookup("TotalAmount","YourQuery","Cust_ID=" & Me.Cust_ID & "")
Where Cust_ID is a unique key.

VB.NET, MySQL & Crystal Report comparative statement between two tables

My two MySQL tables have different information but one field is common. I am showing you the structure of two tables.
I need to show it in a single report filtering by cust_id.
i.e. Customer Id wise billing and payment report.
I tried...
SELECT * FROM billing_info as a,payment_info as b WHERE a.cust_id='1' AND b.cust_id='1' AND a.cust_id=b.cust_id
but rows are repeating.
Hope I explained this properly. Now what should I do ?
Is it possible in Crystal Report to show two tables data ?
I guess ur table structure may resulting duplicate entries.
in table payment_info instead of using the cust_id (reference of cust table), u should use id of table billing_info so that we will get more precised output for ur query.
U also get payment details agains which bill has been made.

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

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