Hi all....I am a novice on access and have a very basic knowledge and I need help with VBA coding. I have made an Access 2003 DB. I have a form with Field1, Field2, Field3, Field4. Field1, Field2, Field3 are address fields, but people have used all 3 fields to insert post codes.
I need a delivery cost to be inserted in Field4 depending on the prefix of the postcode filled in one of the fields in Fields 1,2,3.
The delivery cost is the same for a lot of the postcode prefixes
I will use postcode prefixes AB10-16; AB17-21, BB, BL, DN1-9, DN10, DN11-12, DN13 as an illustration.
a) To AB10-16, BB, BL, DN10, DN13– Delivery cost is £50
b) To AB17-21, DN1-9, DN11-12 - Delivery cost is £60
I have used the following code which works, but is inefficient:
If (Me.Field1.value Like"AB10*" Or Me.Field2.value Like"AB10*" Or Me.Field3.value Like"AB10*") Then Me.Field4.Value = "50"
If (Me.Field1.value Like"AB17*" Or Me.Field2.value Like"AB17*" Or Me.Field3.value Like"AB17*") Then Me.Field4.Value = "60"
But, I have to do this about 250 times for individual prefixes. I would like some help to group them together by giving a group with the same delivery cost a name and using it in the code.
Eg. DeliveryGroup1 = AB10, AB11, AB12, AB13, AB14, AB15, AB16, BB, BL, DN10, DN13
DeliveryGroup2 = AB17, AB18, AB19, AB20, AB21, DN1, DN2, DN3, DN4, DN5, DN6, DN7, DN8, DN9, DN11, DN12
Then use this in the code as below
If (Me.Field1.value Or Me.Field2.value Or Me.Field3.value Like"DeliveryGroup1*") Then Me.Field4.Value = "50"
If (Me.Field1.value Or Me.Field2.value Or Me.Field3.value Like"DeliveryGroup2*") Then Me.Field4.Value = "60"
Can someone please help me with this?
Thank you...Rob
I need a delivery cost to be inserted in Field4 depending on the prefix of the postcode filled in one of the fields in Fields 1,2,3.
The delivery cost is the same for a lot of the postcode prefixes
I will use postcode prefixes AB10-16; AB17-21, BB, BL, DN1-9, DN10, DN11-12, DN13 as an illustration.
a) To AB10-16, BB, BL, DN10, DN13– Delivery cost is £50
b) To AB17-21, DN1-9, DN11-12 - Delivery cost is £60
I have used the following code which works, but is inefficient:
If (Me.Field1.value Like"AB10*" Or Me.Field2.value Like"AB10*" Or Me.Field3.value Like"AB10*") Then Me.Field4.Value = "50"
If (Me.Field1.value Like"AB17*" Or Me.Field2.value Like"AB17*" Or Me.Field3.value Like"AB17*") Then Me.Field4.Value = "60"
But, I have to do this about 250 times for individual prefixes. I would like some help to group them together by giving a group with the same delivery cost a name and using it in the code.
Eg. DeliveryGroup1 = AB10, AB11, AB12, AB13, AB14, AB15, AB16, BB, BL, DN10, DN13
DeliveryGroup2 = AB17, AB18, AB19, AB20, AB21, DN1, DN2, DN3, DN4, DN5, DN6, DN7, DN8, DN9, DN11, DN12
Then use this in the code as below
If (Me.Field1.value Or Me.Field2.value Or Me.Field3.value Like"DeliveryGroup1*") Then Me.Field4.Value = "50"
If (Me.Field1.value Or Me.Field2.value Or Me.Field3.value Like"DeliveryGroup2*") Then Me.Field4.Value = "60"
Can someone please help me with this?
Thank you...Rob