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
- Private Sub Combo74_AfterUpdate()
- Me!DPostCode = Me!Combo74.Column(1)
- Me!Deliver2 = Me!Combo74.Column(2)
- Me!dsiterestrict = Me!Combo74.Column(3)
- Dim strPostCode As String
- Dim varCharge As Variant
- '#############################################
- '######Look up and store the rate number######
- '#############################################
- varCharge = Null
- strPostCode = Nz(Me.DPostCode.Value, "")
- If Len(strPostCode) > 0 Then
- 'PostCode field isn't empty
- If InStr(strPostCode, " ") Then
- 'Trim off the in-code
- strPostCode = Left([strPostCode], 2)
- End If
- 'Look up and store the RateNo
- varCharge = DLookup("[DelRSNo]", "[RatePostcodes]", "[Postcode]='" & strPostCode & "'")
- 'Set the value of the Rates box
- Me.sched.Value = varCharge
- Me.Rate.Value = Nz(DLookup("[Rate]", "RateDetail", "[RateNum] = " & varCharge), 0)
- If Format(Now(), "ww") >= 0 <= 14 Then GoTo Deldays_Week_0_14
- If Format(Now(), "ww") >= 15 <= 28 Then GoTo Deldays_Week_15_28
- If Format(Now(), "ww") >= 29 <= 52 Then GoTo Deldays_Week_29_52
- Deldays_Week_0_14:
- Dim strPostCodeArea As String
- Dim varDeliveryCharge As Variant
- varDeliveryCharge = Null
- strPostCodeArea = Nz(Me.DPostCode.Value, "")
- If Len(strPostCodeArea) > 0 Then
- 'PostCode field isn't empty
- If InStr(strPostCodeArea, " ") Then
- 'Trim off the in-code
- strPostCodeArea = Left([strPostCodeArea], 2)
- 'Select postcode characters to the left
- 'strPostCodeArea = Left(strPostCodeArea, _
- InStr(strPostCodeArea, " ") - 1)
- End If
- 'Look up the postcode
- varDeliveryCharge = DLookup("[EstDelDay]", "[tblEstDelDays1]", "[Postcode]='" & strPostCodeArea & "'")
- 'Set the value of the combo box
- Me.EstDelDay.Value = varDeliveryCharge
- Deldays_Week_15_28:
- Dim strPostCodeArea1 As String
- Dim varDeliveryCharge1 As Variant
- varDeliveryCharge1 = Null
- strPostCodeArea1 = Nz(Me.DPostCode.Value, "")
- If Len(strPostCodeArea) > 0 Then
- 'PostCode field isn't empty
- If InStr(strPostCodeArea1, " ") Then
- 'Trim off the in-code
- strPostCodeArea1 = Left([strPostCodeArea1], 2)
- 'Select postcode characters to the left
- 'strPostCodeArea = Left(strPostCodeArea, _
- InStr(strPostCodeArea, " ") - 1)
- End If
- 'Look up the postcode
- varDeliveryCharge1 = DLookup("[EstDelDay]", "[tblEstDelDays2]", "[Postcode]='" & strPostCodeArea1 & "'")
- 'Set the value of the combo box
- Me.EstDelDay.Value = varDeliveryCharge1
- Deldays_Week_29_52:
- Dim strPostCodeArea2 As String
- Dim varDeliveryCharge2 As Variant
- varDeliveryCharge2 = Null
- strPostCodeArea2 = Nz(Me.DPostCode.Value, "")
- If Len(strPostCodeArea2) > 0 Then
- 'PostCode field isn't empty
- If InStr(strPostCodeArea2, " ") Then
- 'Trim off the in-code
- strPostCodeArea2 = Left([strPostCodeArea2], 2)
- 'Select postcode characters to the left
- 'strPostCodeArea = Left(strPostCodeArea, _
- InStr(strPostCodeArea, " ") - 1)
- End If
- 'Look up the postcode
- varDeliveryCharge2 = DLookup("[EstDelDay]", "[tblEstDelDays3]", "[Postcode]='" & strPostCodeArea2 & "'")
- 'Set the value of the combo box
- Me.EstDelDay.Value = varDeliveryCharge2
- End If
- End If
- End If
- End If
- End Sub
Thanks for taking the time to look at this,
Hope you can help :)