473,499 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting up rate tabels depending on postcode and customer for a haulage company

AdamHope
13 New Member
I am looking to set up some rate tables in MS Access database. I have been banging my head for a few days now.

I will try and explain this as best i can.

The main table is where jobs are put on, you select a customer, select a collection address from a combo box(linked to a collection table), select a delivery address from a combo box (linked to a delivery address table), (which auto drops in the postcode, site restrictions ect) and you select how many pallets will be deliverd to that destination.

I want to set up a rate table for the price to charge the customer depending on the from and to postcode. Depending if part or the whole postcode is entered into the postcode list.
I want to assign rates to customers, If there are no rates set up for that particular customer then it will use the default rates.

I want a postcode list table
(blank "----" cust is default)

-------------------------
| CUS | Posccode | Rate |
-------------------------
| A001| BA | 111 |
| ----| BA | 222 |
| ----| BA12 | 345 |
| A001| CO10 3PZ | 398 |
| ----| CO10 3PZ | 222 |

Rate Table
-----------------------------------------------------
| Rate | RateName | Min pallet | Max pallet | Price |
-----------------------------------------------------
| 111 | Sched 1 | 0 | 2 | £15 |
| 111 | Sched 1 | 3 | 10 | £14 |
| 222 | Sched 2 | 0 | 2 | £18 |
| 345 | Sched 3 | 0 | 5 | £20 |
| 398 | Sched 4 | 0 | 5 | £22 |
| 398 | Sched 4 | 6 | 10 | £19 |

As you can see i have set up bands depending on how many pallets are delivered. The more they have delivered the cheaper it becomes.

So if i was delivering 1 pallet from cus Z056 to postcode BA14 3PN it would be rate 222 between the 0 and 2 min max values and be £18 per pallet.

If it was delivering 3 pallets from cus A001 to posctcode CO10 3PZ it would be rate 398 between 0 and 5 min max values and be £22 per pallet.

How do I tell the main table to look up these values and store them in the field with so many different dependancys? I belive it is with "if" and "dlookup" statements but just keep goin in circles now!!?
I need it to be updated if the address is changed, and also if the amount of pallets is changed.

I have code for the after update of the address combo box. Alot of the commented marks are me playing around on a trial and error basis!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo74_AfterUpdate()
  2. Me!DPostCode = Me!Combo74.Column(1)
  3. Me!Deliver2 = Me!Combo74.Column(2)
  4. Me!dsiterestrict = Me!Combo74.Column(3)
  5.  
  6. Dim strPostCode As String
  7. Dim varCharge As Variant
  8. '#############################################
  9. '######Look up and store the rate number######
  10. '#############################################
  11.     varCharge = Null
  12.     strPostCode = Nz(Me.DPostCode.Value, "")
  13.     If Len(strPostCode) > 0 Then
  14.     'PostCode field isn't empty
  15.     If InStr(strPostCode, " ") Then
  16.     'Trim off the in-code
  17.     strPostCode = Left([strPostCode], 2)
  18.     End If
  19.     'Look up and store the RateNo
  20.     varCharge = DLookup("[DelRSNo]", "[RatePostcodes]", "[Postcode]='" & strPostCode & "'")
  21.     'Set the value of the Rates box
  22.     Me.sched.Value = varCharge
  23.     Me.Rate.Value = Nz(DLookup("[Rate]", "RateDetail", "[RateNum] = " & varCharge), 0)
  24.  
  25. If Format(Now(), "ww") >= 0 <= 14 Then GoTo Deldays_Week_0_14
  26. If Format(Now(), "ww") >= 15 <= 28 Then GoTo Deldays_Week_15_28
  27. If Format(Now(), "ww") >= 29 <= 52 Then GoTo Deldays_Week_29_52
  28.  
  29. Deldays_Week_0_14:
  30.     Dim strPostCodeArea As String
  31.     Dim varDeliveryCharge As Variant
  32.     varDeliveryCharge = Null
  33.     strPostCodeArea = Nz(Me.DPostCode.Value, "")
  34.     If Len(strPostCodeArea) > 0 Then
  35.     'PostCode field isn't empty
  36.     If InStr(strPostCodeArea, " ") Then
  37.     'Trim off the in-code
  38.     strPostCodeArea = Left([strPostCodeArea], 2)
  39.     'Select postcode characters to the left
  40.     'strPostCodeArea = Left(strPostCodeArea, _
  41.     InStr(strPostCodeArea, " ") - 1)
  42.     End If
  43.     'Look up the postcode
  44.     varDeliveryCharge = DLookup("[EstDelDay]", "[tblEstDelDays1]", "[Postcode]='" & strPostCodeArea & "'")
  45.     'Set the value of the combo box
  46.     Me.EstDelDay.Value = varDeliveryCharge
  47.  
  48. Deldays_Week_15_28:
  49.     Dim strPostCodeArea1 As String
  50.     Dim varDeliveryCharge1 As Variant
  51.     varDeliveryCharge1 = Null
  52.     strPostCodeArea1 = Nz(Me.DPostCode.Value, "")
  53.     If Len(strPostCodeArea) > 0 Then
  54.     'PostCode field isn't empty
  55.     If InStr(strPostCodeArea1, " ") Then
  56.     'Trim off the in-code
  57.     strPostCodeArea1 = Left([strPostCodeArea1], 2)
  58.     'Select postcode characters to the left
  59.     'strPostCodeArea = Left(strPostCodeArea, _
  60.     InStr(strPostCodeArea, " ") - 1)
  61.     End If
  62.     'Look up the postcode
  63.     varDeliveryCharge1 = DLookup("[EstDelDay]", "[tblEstDelDays2]", "[Postcode]='" & strPostCodeArea1 & "'")
  64.     'Set the value of the combo box
  65.     Me.EstDelDay.Value = varDeliveryCharge1
  66.  
  67. Deldays_Week_29_52:
  68.     Dim strPostCodeArea2 As String
  69.     Dim varDeliveryCharge2 As Variant
  70.     varDeliveryCharge2 = Null
  71.     strPostCodeArea2 = Nz(Me.DPostCode.Value, "")
  72.     If Len(strPostCodeArea2) > 0 Then
  73.     'PostCode field isn't empty
  74.     If InStr(strPostCodeArea2, " ") Then
  75.     'Trim off the in-code
  76.     strPostCodeArea2 = Left([strPostCodeArea2], 2)
  77.     'Select postcode characters to the left
  78.     'strPostCodeArea = Left(strPostCodeArea, _
  79.     InStr(strPostCodeArea, " ") - 1)
  80.     End If
  81.     'Look up the postcode
  82.     varDeliveryCharge2 = DLookup("[EstDelDay]", "[tblEstDelDays3]", "[Postcode]='" & strPostCodeArea2 & "'")
  83.     'Set the value of the combo box
  84.     Me.EstDelDay.Value = varDeliveryCharge2
  85. End If
  86. End If
  87. End If
  88. End If
  89. End Sub
  90.  
If there is anything i have missed out or not explained properly please let me know,

Thanks for taking the time to look at this,

Hope you can help :)
Aug 11 '10 #1
3 2173
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. It seems to me that you've set yourself somewhat of an impossible task; you want to be able to set up a rate table which defines the rate given the collection and delivery postcodes of a delivery. However, the possible combinations of postcodes involved run into billions (there are approx 1.8 million postcodes in the UK, so think of approx (2x10^6)^2 combinations).

In any event, your postcode element is only a proxy for the distance involved - and it is the distance which should in the main determine the rate.

Given the use of a postcode database - such as the Postzon data Royal Mail licences commercially on an annual basis - you would have access to the easting and northing (the x and y co-ordinate) of every address in the database. Given the to- and -from address eastings and northings it is possible to compute the distance between them as a straight-line approximation, and base your price bands on the distance travelled.

More complex approaches using sat-nav type road databases could give you actual distances between two postcodes, but at root the same technique is being used: compute the distance between nodes on the network, not work out all possible combinations of start and end postcodes to devise rate tables.

In the end, you want to keep the look-up task simple and maintainable. A rate table does not have to be complex, and should not require a battery of VBA code to make it work.

-Stewart
Aug 11 '10 #2
AdamHope
13 New Member
Hi Stewart, Thanks for your reply,

I think that this is a good idea. I do have some code that plots the co-ordinate's to my address by linking to microsoft mappoint and saves these in the table along side the address, but am unsure how i would get it to calculate the distances between 2 points in Access.

Would i still be able to set up different costs depending on the customer? Also Would still need the price bands depending on pallets delivered (Gets cheaper the more they want delivering).

I wanted to set up rate tables like this because this is how they are set up in another ms access database i have seen this done similar to this - i just havent seen the code behind the forms :(

Your help is much appreciated,

Adam
Aug 12 '10 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. The differences between the to- and from-address eastings and northings tell you (in km) how distant the two points are from each other in the two directions (east-west and north-south). You need to understand what eastings and northings mean - they are distances in km from an arbitrary point located (if I remember) to the south-west of England, and define how far east and north all other reference points are located. Ordnance Survey (amongst others) have reference material on this on their web site. So do Royal Mail, who explain also to what accuracy their eastings and northings are quoted - in the least-expensive cases it is to the nearest 100m.

It is possible to convert these from rectangular co-ordinate form to polar co-ordinates (from x, y to distance and angle) which gives you the distance directly. You can find the details on how to convert rectangular to polar co-ordinates by looking up any suitable reference source (e.g. Wikipedia). Such approximations are fine for computing distance for your needs - you don't need to look into the complexity of converting eastings and northings to true latitude and longitude, for instance, which is sometimes necessary for mapping purposes.

You should have a separate volume discount table to store the business rule that specifies the default discount for the number of palates bought. This is just a table storing the thresholds at which you apply particular discounts. For example, if 20 palates would trigger a 20% discount and 40 palates 30%:

Expand|Select|Wrap|Line Numbers
  1. Threshold Discount
  2.       0         0
  3.      20       0.2
  4.      40       0.3
-Stewart
Aug 12 '10 #4

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

Similar topics

2
1543
by: skeeterbug | last post by:
i have a program that will display a number of diffferent results depending on the situation. one example of the code looks like <?php if(isset($_SESSION)) { print 'You entered: ' ....
2
8298
by: Manmohan S. Sihra | last post by:
Hello, I need your help. I have to integrate FedEx or UPS's Rate Calculator with an eCommerce web site. I have a web site which offers some products for sale. The price of the products is being...
11
2096
by: reciprocity85 | last post by:
Hello all. I have a question about what you all get paid, and what I should expect in my situation. I googled quite a bit, but not come up with any benchmarks definite enough that I would want...
5
12969
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
6
3503
by: RobR | last post by:
We have a customer using our application that has a problem. Within our app, we have a two different forms (one generates an email, the other a fax via a webservice). When they click the submit...
6
3359
by: Julian | last post by:
Hi, I am a very beginner in databases. I created a database table in Access 2003 and OOo 2.03 that includes name, address, postcode, phone numbers etc of our customers. I would like to sort...
15
2263
by: bb nicole | last post by:
The company profile showed blank after user login and click the company profile button. Supposed the company profile should not be blank and will show the company information which call from...
12
1896
by: xhe | last post by:
I am now developing a website which needs Canadian PostCode Database. I can certainly buy one, but that will cost my hundered of $$, and my website is only for education purpose, it won't make...
1
2022
by: dominicowen | last post by:
Hi, I have a customer database in Access 2003 with customers postcodes. What I want to do is type in a postcode on access and it will link the postcode on to googlemaps without having to type...
10
9632
by: =?Utf-8?B?SmFtZXMgV29uZw==?= | last post by:
Hi everybody, I'm trying to use the new VB 2008 right now and I want to know how to preset the company name and copyright informtion in Assembly Information. In my current VB 2005, company name...
0
7132
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
7009
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...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.