Shipping Calculations

Nicolette

Always Learning
Local time
Today, 12:24
Joined
Jun 26, 2010
Messages
178
I'm not sure if this is the right place for this post... If not i'm sorry!

$2.00 for first item $0.25 for each additional these amounts are variable depending upon the shipping method picked

How would I calculate this I'm thinking with a count of the items.... Maybe?:confused:
 
Re: Shipping Calcuations

I guess the maths are:

ShippingCost = 2 + (((Count([OrderQty])-1)*.25)

or similar.

[OrderQty] can be any field on your form that shows order details.

If you want to store this value (shipping cost) then I guess another field should be added to tblOrderHeader.

Do you have Back orders??
 
Re: Shipping Calcuations

The shipping costs should not be hard coded in. You should have a table to store the current cost amounts so that your calculation can use them. And yes, you will want to store the shipping cost unless you want to go through the extra hassle of storing the shipping cost effective dates and then calculating on the fly with that. I would think that wouldn't be the best way to do it, even though it is the more normalized way, it isn't the best in practice. Storing the cost in this case is good to do.

But as I said, the actual amounts to use in the calculation should be stored in a table and retrieved to calculate the amounts at the time you are calculating it. That way you don't need to change the programming to change shipping costs; only make record changes within a table.
 
Re: Shipping Calcuations

ok so I was close....

I don't see a need to store the amount just the method.....
this would be best hadled by a table right

tblShipping
MethodID(PK)
MethodName
MethodStartFee
MethodAddFee

Something like that right?

no not as of right now but i'm sure it is something I will have to contend with once the wholesale aspect is up and running I only have 2 people who buy wholesale right now and their orders are minimal
 
Re: Shipping Calcuations

The shipping costs should not be hard coded in. You should have a table to store the current cost amounts so that your calculation can use them. And yes, you will want to store the shipping cost unless you want to go through the extra hassle of storing the shipping cost effective dates and then calculating on the fly with that.

Oh ok I see like with the sales tax from earlier for historical invoice purposes
 
Re: Shipping Calcuations

Oh ok I see like with the sales tax from earlier for historical invoice purposes
Yes, sort of like that. It is also like how you would store the price of an item because in two months the price might change and if you didn't store the price and then went to get the calculation, it would say one thing but wouldn't be the price you charged.

I have a sample database which shows how you can use a table with an "EFFECTIVE DATE" for storing prices, but in the long run it is much more of a pain than just storing the price to begin with. :)
 
Re: Shipping Calcuations

ShippingCost = 2 + (((Count([OrderQty])-1)*.25)

ok so how would I do that calculation dependent upon the method that is picked

I have another choice that is $6.50 for the first and $0.25 each additional

could I use the field names in place of the numbers?
 
Re: Shipping Calcuations

ok so how would I do that calculation dependent upon the method that is picked

I have another choice that is $6.50 for the first and $0.25 each additional

could I use the field names in place of the numbers?

I would just use a custom function to do it.

So you could have a table like this:

tblShippingRates
ShippingRateBase - Currency
ShippingRateAdditional - Currency


Or if you have a separate base and additional rate for different types of items you could use

tblShippingRates
ShippingRateID - Autonumber (PK)
ProductID - Long Integer (FK)
ShippingRateBase - Currency
ShippingRateAdditional - Currency

And then you just have a function with:

Code:
Function GetRate(lngProdID As Long, lngQty As Quantity) As Currency
   Dim strSQL As String
   Dim rst As DAO.Recordset
   
   Set strSQL = "Select ShippingRateBase, ShippingRateAdditional " & _
                     "FROM tblShippingRates " & _
                     "WHERE ProductID = " & lngProdID

   Set rst = CurrentDb.OpenRecordset(strSQL)
 
   GetRate = rst!ShippingRateBase + ((lngQty -1) * rst!ShippingRateAdditional
   
   rst.Close
   set rst = Nothing
End Function

And then you can just use it in a query by

ShipRate: GetRate([ProductID], [Qty])
 
Last edited:
Re: Shipping Calcuations

Or if you have a separate base and additional rate for different types of items you could use

tblShippingRates
ShippingRateID - Autonumber (PK)
ProductID - Long Integer (FK)
ShippingRateBase - Currency
ShippingRateAdditional - Currency

That is good to know because as I expand my inventory to include other items they very well may need to be charged shipping differently mental note for the future
 
Re: Shipping Calcuations

That is good to know because as I expand my inventory to include other items they very well may need to be charged shipping differently mental note for the future

Note my additional changes up above as I accidentally posted (hit enter) before I was through.
 
Re: Shipping Calcuations

oh heavens I have never even touched codes like that.... I have tried to do everything I can to avoid it.....
 
Re: Shipping Calcuations

It really isn't as bad as it looks. We can walk you through it, if you are willing.
 
Re: Shipping Calcuations

I'm sure it isn't especially since I know some PHP... Yes i'm willing to learn I just worry that I come across as a complete idot and that I shouldn't even be messing around with it
 
Re: Shipping Calcuations

I was thinking should I just implament the shipping that varies on the product now to save my self the hassel i'm sure it will cause it to have problems in the future...
 
Re: Shipping Calcuations

I'm sure it isn't especially since I know some PHP... Yes i'm willing to learn I just worry that I come across as a complete idot and that I shouldn't even be messing around with it

Hey no worries - remember we all had to start somewhere. It didn't just automatically "happen" for us either. :)

So, to explain the function that I have built there, we first say that we are wanting to get a total shipping cost. This is just one way you can do it, however.

The function starts off by declaring a few things.

Function GetRate(lngProdID As Long, lngQty As Quantity) As Currency

So, the name of the function is GetRate and because it just says FUNCTION (instead of PRIVATE FUNCTION, it is a PUBLIC function. You can also use PUBLIC FUNCTION GetRate to declare as public.)

The lngProdID is declared as a long integer (which is the datatype that the product ID is (or should be) in our table. lngQty is declared as long but could probably have been just Integer but it is good to be consistent so we kept both integers to longs. And finally the As Currency means that we will be returning a value which will be returned as a Currency datatype.

I'll continue the explanation in another post.
 
Re: Shipping Calcuations

And the next part -

We will declare the variables which we need to use in just a little bit:
Code:
   Dim strSQL As String
   Dim rst As DAO.Recordset

We will need a SQL string so we have that first declaration and then we want to use a DAO Recordset so we declare one. It is best to be explicit (saying ADODB or DAO) when declaring recordsets and Access 2007 and above is more picky about that than ever before.

Next, is just assigning the SQL query to the strSQL variable. If you notice, we have a few & _ at the end of the lines. This is to continue the lines and it can be done in several ways. You can use a line continuation _ without the ampersand (&) but you can't indent the rest like I have done if you don't "concatenate" the strings like I'm doing by using the ampersands. I like to indent it so it is easier to read. I also split them up by the Select, the From, the Where, the Group By, and the Order By on each line so that it is easier to read. I do have a typo in the original which I'll need to go fix. You don't use SET with a string variable so I'll need to change it to what I have below:
Code:
         strSQL = "Select ShippingRateBase, ShippingRateAdditional " & _
                     "FROM tblShippingRates " & _
                     "WHERE ProductID = " & lngProdID

Also, note that the variable is OUTSIDE of the quotes in the string so that we can ensure that the VALUE of the string is used. It can be possible at times to leave it inside of the quotes but I never do just to ensure proper handling and passing of values.


to be continued...
 
Re: Shipping Calcuations

And the last part of this....


Code:
   Set rst = CurrentDb.OpenRecordset(strSQL)
 
   GetRate = rst!ShippingRateBase + ((lngQty -1) * rst!ShippingRateAdditional
   
   rst.Close
   set rst = Nothing

We set the recordset variable by opening a recordset from the CurrentDb. We do that by passing the SQL string that we created and assigned to the strSQL variable. Once we have that (and we are expecting ONE record - and we could do a test to ensure that we have a record and only one, but we'll leave that for now) we can then read the values and use them in our calculation to get the total shipping cost.

We are doing the calculation AND assigning the total to the Function by using

Code:
  GetRate = rst!ShippingRateBase + ((lngQty -1) * rst!ShippingRateAdditional

Which it is assigned to the function by using the name of the function on the left of the equals sign and then we use the values. How we do that is by using the name of the recordset object (rst in this case) and the BANG operator.

You could also use rst.Fields("ShippingRateBase").Value
or
rst("ShippingRateBase").Value

as well. I just use the rst!ShippingRateBase as the one that I like.

So for the base we just need the base value and then we also need the quantity (which we've passed to us to use as lngQty) but minus one (-1) since it is for each additional item. And then that is multiplied by the ShippingRateAdditional which is gathered by again using rst!ShippingRateAdditional.

The last part is we close the recordset and then destroy the recordset variable (doing some "clean up work") by using Set rst = Nothing.

And that is it. Any questions?
 
Re: Shipping Calcuations

Ok I'm pretty sure I follow you in all that.... and you would call this function in the form?
also Would i need to build that actual query or is that what that function is doing is building the query
 
Re: Shipping Calcuations

Ok I'm pretty sure I follow you in all that.... and you would call this function in the form?
also Would i need to build that actual query or is that what that function is doing is building the query
You can call the function wherever it was appropriate. You probably would want it on the form when you are adding the shipping in.
 
Re: Shipping Calcuations

lShippingRates
ShippingRateID - Autonumber (PK)
ProductID - Long Integer (FK)
ShippingRateBase - Currency
ShippingRateAdditional - Currency

what would be the best way to identify the type of product?

Should I have another table with the types of products?

right now I sell itty bitty pieces of jewlery but i'm adding a makeup line so that would be 2 types of product

The tblInventory already has a type field that I was currently using to specify the type of charm the piece was but that isn't really important could I just use that same field and change the purpose? This would work by an ID number assigned to the product not the SKU for each product right?

I just want to make sure I completely understand this because I don't want to get lost in it and then spend 3 days trying to figure out where i got lost to spend another 3 days trying to get unlost
 

Users who are viewing this thread

Back
Top Bottom