Calculation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sujitbhattacharya
    New Member
    • Feb 2008
    • 3

    Calculation

    Dear Community

    Sir I have two fields in a table and both of them are of number Data Type (as per ACCESS format). The following is the code Through which I'm trying to enter a calculated data in the Table

    [CODE=vb]Dim Bal_Stock1 As Double
    Dim STOCK As Integer
    Dim Issued As Integer
    Dim Quantity_Stock As Integer
    Dim Quantity_Issued As Integer
    Dim Bal_Stock As Integer

    Quantity_Stock = STOCK
    Quantity_Issued = Issued
    Bal_Stock = Bal_Stock1

    Bal_Stock1 = stbal(STOCK, Issued)
    MsgBox (stbal(CDbl(STO CK), CDbl(Issued)))

    sql = "INSERT INTO stock(Item_code ,Item_Name,Quan tity_Stock,Unit ,StockValue,Qua ntity_issued,un it1,IssuedValue ,Bal_Stock,Unit 2,StockValue1)V ALUES(" & _
    "' " & txtItem_Code.Te xt & "',' " & txtItem_Name.Te xt & " '," & Quantity_Stock & ",' " & txtUnit.Text & "','" & txtStockValue.T ext & "'," & Quantity_Issued & ",' " & txtUnit1.Text & "','" & txtIssuedValue. Text & "', " & Bal_Stock & ",'" & txtUnit2.Text & "',' " & txtstockValue1. Text & "') "[/CODE]

    Following is the function through which the calculation is done

    [CODE=vb]Function stbal(STOCK As Integer, Issued As Integer) As Double
    stbal = STOCK - Issued

    End Function[/CODE]

    With this above code it is giving

    Error "DataType mismatch on criteria expression"

    Pls help me
    Last edited by Killer42; Mar 28 '08, 09:43 AM. Reason: Added CODE=vb tags
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by sujitbhattachar ya
    Dear Community
    ...
    MsgBox (stbal(CDbl(STO CK), CDbl(Issued)))
    ...
    Function stbal(STOCK As Integer, Issued As Integer) As Double
    stbal = STOCK - Issued
    End Function
    ...
    Error " DataType mismatch on criteria expression"

    Pls help me
    CDbl will transform the expression into a Double
    stbal use Integers as an input

    maybe you should use
    stbal(stock, issued)
    since they're integers and you dont need to make them doubles for the function to work.

    HTH

    Comment

    Working...