473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to search and compare the data from three tables in a form

Hi,
I have three tables: Table A, Table B and Table C
Fields of Table A: Truck No, Capacity
Fields of Table B: Consignee ID, Capacity A, Capacity B and
Capacity C
Fields of Table C: Consignee ID, Final Rate

Input form is based on Table C:
1-I select Truck No using a combo box and it shows the Capacity from Table A using DLookup.
2- I enter the id no. in the field of Consignee ID and it returns the values of Capacity A, Capacity B and Capacity C using DLookup from Table B.
So I have to write manually one final rate in the field of Final Rate in the form.
So I want:
When I enter id no. in the field of Consignee ID, it matches with the Capacity in Table A and shows the matched result only in the field of Final Rate of Table C.

Prompt assistance will be highly appreciated.

Thanks
Oct 19 '14 #1
5 1259
Luuk
1,047 Expert 1GB
- It's unclear how 'capacity' and 'rate' are related

"When I enter id no. in the field of Consignee ID, it matches with the Capacity in Table A and shows the matched result only in the field of Final Rate of Table C."
- It's unclear what 'the matched result' is, because there are 3 columns with 'capacity' in TableB

Tip: give your table names a meaningful name, in stead of 'Table A' you could user 'Truck'
Oct 19 '14 #2
I am so sorry for not being so clear. As I am new to Access so please bear me. I am trying my best to give the details so please advice accordingly.

I have three tables:
1-Truck details,
2-Consignees
3-Main
Fields of Truck details: Truck No, Capacity
Fields of Consignees: Consignee ID, 43000L, 27000L and
21000L
Fields of Table Main: Consignee ID, Final Rate

Input form(Main Form) is based on Table Main
Main Form:
1-I select Truck No using a combo box and it shows the Capacity from Table Truck Details using DLookup.
2- I enter the id no. in the field of Consignee ID and it returns all the values of 43000L, 27000L and 21000L using DLookup from Table Consignees.
So I have to write manually one final rate in the field of Final Rate in the form.
I want:
When I enter id no. in the field of Consignee ID, it matches with the Capacity in Table Truck details and show the related value from(43000L, 27000L and 21000L)Consignees in the field of Final Rate of Table Main.
Like:
If Consignee ID is = 1 and its Capacity is (43000L) from Truck details Then
Show only the rate of 43000L from Table Consignees in the Final Rate field of Table main. All are present on the Main Form

Once again sorry and please help
Oct 19 '14 #3
twinnyfo
3,653 Expert Mod 2GB
1. It sounds like your tables may not be properly normalized. Please review this article (Database Normalization)

2. It seems like you keep wanting to use DLookup when you don't have to. This is highly inefficient. If your Combo Box selects a truck, why not just include the capacity of that truck in your list of columns? There should never be a need for you to select a truck (from a list of trucks in your table), and then have that value use a DLookup to find other details about that same truck from the same table.

3. If this is the case, however, after you have selected the truck, you should repopulate the Combo box for the consignee based on the size of the truck (reset the row source for the combo box). Then, when you select the consignee--use a combo box again--don't "type in" the consignee id--the value returned in the combo box will be the rate for the same size of truck. Then, update that value into your final rate.
Oct 19 '14 #4
Your article is quiet nice. Can you advice me what to do now please? Sorry I am very new to access.
Please assist me accordingly
Oct 20 '14 #5
twinnyfo
3,653 Expert Mod 2GB
Here is my quick recommendation for your tables:

tblTrucks - Your Table A
Expand|Select|Wrap|Line Numbers
  1. Field    Type              Notes
  2. TruckID  Long, AutoNumber  Primary Key
  3. TruckNo  Text              Could be "10", or "10A" depending on your truck number convention--or, it could be an Integer data type
  4. TruckCap Long              Truck Capacity in Liters


tblConsigneeRates - Your Table B
Expand|Select|Wrap|Line Numbers
  1. Field          Type              Notes
  2. RateID         Long, AutoNumber  Primary Key
  3. ConsigneeID    Long, AutoNumber  Foreign Key to tblConsignees
  4. TruckCap       Long              Truck Capacity in Liters
  5. ConsigneeRate  Currency          How much you charge this Consignee for this size truck


tblInvoices - Your Table C
Expand|Select|Wrap|Line Numbers
  1. Field        Type              Notes
  2. InvoiceID    Long, AutoNumber  Primary Key
  3. ConsigneeID  Long, AutoNumber  Foreign Key to tblConsignees
  4. FinalRate    Currency          How much this Consignee is charged on this Invoice
  5. InvoiceDate  Date              Date of Invoice
  6. etc......


tblConsignees - New Table
Expand|Select|Wrap|Line Numbers
  1. Field             Type              Notes
  2. ConsigneeID       Long, AutoNumber  Primary Key
  3. ConsigneeName     Text
  4. ConsigneeAddress  Text
  5. Etc.....
Your Form should be bound to tblInvoices. When you move to a new record, you can use the following Combo Boxes.

On your Form, have a combo Box (cboTruck) with three columns, Row Source is:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tblTrucks;
When you select a truck, you will want to be able to select consignees, based on the size of the selected truck. So, you will also have another Combo Box (cboConsignee) with three columns.

In the AfterUpdate Event of that Combo Box, use the following VBA:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboTruck_AfterUpdate()
  2.     Dim strSQL As String
  3.     strSQL = "SELECT RateID, ConsigneeID, ConsigneeRate " & _
  4.         "FROM tblConsigneeRates " & _
  5.         "WHERE TruckCap = " & Me.cboTruck.Column(2) & ";"
  6.     With Me.cboConsignee
  7.         .RowSource = strSQL
  8.         .Requery
  9.     End With
  10. End Sub
Then, when you select a Consignee from that Combo Box, you want to save the Consignee data to the Table, along with the rate charged on this invoice.

In the AfterUpdate Event of that Combo Box, use the following VBA:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboConsignee_AfterUpdate()
  2.     Me.cboInvoiceConsignee = Me.cboConsignee.Column(1)
  3.     Me.txtFinalRate = Me.cboConsignee.Column(2)
  4. End Sub
This assumes that your form has a bound combo box (cboInvoiceConsignee) that uses ConsigneeID as a foreign Key and a bound Text Box for the FinalRate. Then just add other controls for the date of the invoice, etc.

I hope this made sense.

It is a much more direct method for assigning proper invoice values.

Please note, I have not tested this code, and only freehanded it, but it should get you in the right direction with your project.
Oct 20 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: EMW | last post by:
Hi, I have an Oracle database with different tables of data. They all have one common field. I need to combine some fields from three tables. i.e. field1 and field2 from table1 field3 and...
3
by: Leo | last post by:
I am trying to determine the changes an application makes to a database. The plan is to copy the existing schema (active) to a reference schema, run the application and then diff the table data...
0
by: WindAndWaves | last post by:
Hi Gurus Here is another question that I have been struggling with for over a year. Basically, I would like to allow users to enter data into three tables in at the same time. The reason it...
3
by: Carmela | last post by:
Hello Readers, I am trying to update data on a form that is based on a query having a many-to-one-to-many relationship. I found this exciting link that seemed to have the solution for me: ...
16
by: Andy_Khosravi | last post by:
I'm in a bit of a pickle. My employer, a health insurance firm, had me design a small database to track benefit issues. The intended users were technical specialists and some managers (about 90...
0
by: Mike | last post by:
I have a form that has a search button on it. The form has three text boxes, last name, first name, and bidder number. I put in a last name and click the search button. Clicking the search button...
6
by: John | last post by:
Hi I have three tables with a common id with which they can be linked. I need to merge them in a way that the resultant table has all records from three tables. Below is what sort of result I am...
11
by: khushbubhalla | last post by:
how to compare data between tables and views row by row , column by column in the test and production environment
7
by: cov | last post by:
I have a php query where I'm attempting to pull data from 3 different tables between a php form and mysql db. I had hoped early on to use a unique identifier to help ensure referential integrity...
1
by: anna brown | last post by:
hi there, i have three tables with independent data. example: table 1: red, white, green, .... table 2: big, small, large, .... table 3: Mary, Adam, John, ... I need to create a form with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.