igendreau
10-13-2015, 11:22 AM
I have a piece of code that I didn't write that I need some help debugging. I get an overflow error when I open my form, but only if the quantity on that record is high, for instance 70000. The error occurs on the following line:
get_avl_product = rs("TotalAvailable") + Newqty
Here's the entire function:
Function get_avl_product(ByRef ProductID As Integer, Newqty As Integer, Oqty As Integer) As Integer
' We alway add back in the original qty that was on the pull list when
' calculating the available product
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sql As String
sql = "Select (products.quantity1 - SUM(IIF(ISNULL(pulldetails.quantity),0,pulldetails.quantity))) as TotalAvailable from Products " _
& " Left Outer Join pulldetails on pulldetails.productid = products.productid " _
& " where products.productid = " & ProductID _
& " Group by Products.Productid, Products.quantity1 "
rs.Open sql, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If rs.EOF And rs.BOF Then
get_avl_product = Newqty - Oqty
Else
If IsNull(rs("TotalAvailable")) Then
get_avl_product = Newqty - Oqty
Else
get_avl_product = rs("TotalAvailable") + Newqty
End If
End If
Set rs = Nothing
products.quantity1 mentioned in my SELECT statement is a long integer. So I'm assuming there is something about the SELECT statement's handling of TotalAvailable that is not allowing it to process that big a number. The function works just fine for small numbers. Can anyone tell me how to tweak this code to allow for these bigger numbers?
get_avl_product = rs("TotalAvailable") + Newqty
Here's the entire function:
Function get_avl_product(ByRef ProductID As Integer, Newqty As Integer, Oqty As Integer) As Integer
' We alway add back in the original qty that was on the pull list when
' calculating the available product
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sql As String
sql = "Select (products.quantity1 - SUM(IIF(ISNULL(pulldetails.quantity),0,pulldetails.quantity))) as TotalAvailable from Products " _
& " Left Outer Join pulldetails on pulldetails.productid = products.productid " _
& " where products.productid = " & ProductID _
& " Group by Products.Productid, Products.quantity1 "
rs.Open sql, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If rs.EOF And rs.BOF Then
get_avl_product = Newqty - Oqty
Else
If IsNull(rs("TotalAvailable")) Then
get_avl_product = Newqty - Oqty
Else
get_avl_product = rs("TotalAvailable") + Newqty
End If
End If
Set rs = Nothing
products.quantity1 mentioned in my SELECT statement is a long integer. So I'm assuming there is something about the SELECT statement's handling of TotalAvailable that is not allowing it to process that big a number. The function works just fine for small numbers. Can anyone tell me how to tweak this code to allow for these bigger numbers?