Results 1 to 23 of 23

Thread: SQL Statement Count Total Quantity

Hybrid View

  1. #1
    Addicted Member
    Join Date
    Aug 2004
    Posts
    176

    Re: SQL Statement Count Total Quantity

    You are doing a
    VB Code:
    1. Do Until rst.EOF
    Then inside this you are again defining
    VB Code:
    1. DisplaySQL = "SELECT * FROM DataGrid"
    2.         Set rst = oSQL.Execute(DisplaySQL)
    This would reset the recordset. The .Movenext would no more be effective. Don't set it again.

  2. #2

    Thread Starter
    Lively Member carlovfrimily's Avatar
    Join Date
    Jan 2005
    Location
    Malaysia
    Posts
    123

    Re: SQL Statement Count Total Quantity

    How about this?

    VB Code:
    1. Private Sub DisplayGrid ()
    2. i = 0
    3. fg.Clear
    4.     sSQL = "SELECT * FROM PackQty_View "
    5.     Set oRs1 = oShip.Execute(sSQL)
    6.     Qty = oRs1!Qty
    7.     ModelDefined = oRs1!ModelDefined
    8.  
    9.    DisplaySQL = "SELECT Model,TargetQty,Exceed FROM DataGrid"
    10.    Set rst = oSQL.Execute(DisplaySQL)
    11.  
    12.     fg.ColWidth(0) = 2900
    13.     fg.ColWidth(1) = 1600
    14.    
    15.     fg.ColAlignment(0) = flexAlignLeftCenter
    16.     fg.ColAlignment(1) = flexAlignLeftCenter
    17.  
    18.     Row = 0
    19.    
    20.     fg.TextMatrix(Row, 0) = "Model"
    21.     fg.TextMatrix(Row, 1) = "Total Quantity"
    22.    
    23.     Row = Row + 1
    24.    
    25. Do Until rst.EOF
    26.  
    27.     fg.Rows = rst.RecordCount + 1
    28.     fg.TextMatrix(Row, 0) = rst!Model
    29.  
    30.  
    31.     If fg.TextMatrix(Row, 0) <> oRs1!ModelDefined Then
    32.                 Qty = 0
    33.             Else
    34.                 Qty = oRs1!Qty
    35.             End If
    36.            
    37.  
    38.         TargetQty = rst!TargetQty
    39.         Exceed = rst!Exceed
    40.         sTotal = Qty + Exceed
    41.  
    42.         fg.TextMatrix(Row, 1) = sTotal
    43.  
    44.         If fg.TextMatrix(Row, 1) < TargetQty Then
    45.          fg.Row = Row
    46.          fg.Col = 1
    47.          fg.CellBackColor = vbRed
    48.  
    49.         ElseIf fg.TextMatrix(Row, 1) >= TargetQty Then
    50.          fg.Row = Row
    51.          fg.Col = 1
    52.          fg.CellBackColor = vbGreen
    53.         End If
    54.  
    55.         Row = Row + 1
    56.         rst.MoveNext
    57.    
    58. Loop
    59. Exit Sub
    60. End Sub
    Human Knowledge Belongs To The World

  3. #3

    Thread Starter
    Lively Member carlovfrimily's Avatar
    Join Date
    Jan 2005
    Location
    Malaysia
    Posts
    123

    Re: SQL Statement Count Total Quantity

    May I know where is my mistakes?
    Human Knowledge Belongs To The World

  4. #4

    Thread Starter
    Lively Member carlovfrimily's Avatar
    Join Date
    Jan 2005
    Location
    Malaysia
    Posts
    123

    Re: SQL Statement Count Total Quantity

    Do Until rst.EOF

    fg.Rows = rst.RecordCount + 1
    fg.TextMatrix(Row, 0) = rst!Model
    fg.TextMatrix(Row, 1) = rst!TargetQty
    ' Row = Row + 1

    If fg.TextMatrix(Row, 0) <> ModelDefined Then 'How to write the coding to compare with the two row of ModelDefined instead of comparing only with the first row of ModelDefined here? Qty = 0
    Else
    Qty = oRs1!Qty
    End If

    TargetQty = rst!TargetQty
    OnHand = rst!OnHand
    sTotal = Qty + OnHand

    fg.TextMatrix(Row, 2) = sTotal

    If fg.TextMatrix(Row, 2) < TargetQty Then
    fg.Row = Row
    fg.Col = 2
    fg.CellBackColor = vbRed

    ElseIf fg.TextMatrix(Row, 2) >= TargetQty Then
    fg.Row = Row
    fg.Col = 2
    fg.CellBackColor = vbGreen
    End If

    Row = Row + 1
    rst.MoveNext

    Loop
    Human Knowledge Belongs To The World

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width