Results 1 to 23 of 23

Thread: [RESOLVED] What's missing?

Threaded View

  1. #1

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Resolved [RESOLVED] What's missing?

    I have following textboxes: txtcode,txtsupply, txtdesc,and txtQty. I enter a code in txtcode and automatically the txtdesc will display item description and also the txtsupply will display the supply available (I'm getting the value from DB).

    I will type quantity to be sold in the txtQty and then click the additem button to add/display the said item in list of items to be sold using a listview. I have codes in my listview to allow me to double click any item for editing purposes (change the quantity to be sold i.e. from 5 and make it 2 or from 5 make it 10).

    Now my concerns is this when I double click an item the txtsupply value is not adding back 5 to the DB which should be reflected in txtsupply.

    Example:
    Supply = 105
    quantity to be sold = 5

    so when I click additem automatic 5 will be subracted from number of supply and become 100.

    I will double click the item in the listview txtsupply will still be 100 But supposedly it should display 105.

    What am i missing with my codes?
    VB Code:
    1. Private Sub txtCode_Change()
    2.   txtQty.Text = ""
    3.   txtDiscount.Text = ""
    4.  
    5.   If InStr(1, txtCode.Text, "*") = Len(txtCode.Text) Then
    6.     txtQty.SetFocus
    7.   End If
    8.  
    9.   If rsStocks.State = adStateOpen Then rsStocks.Close
    10.  
    11. On Error Resume Next
    12.   If txtCode.Text <> "" Then
    13.     rsStocks.Open "SELECT * FROM tblStocks WHERE Code = '" & txtCode.Text & "'", oConn, adOpenStatic, adLockOptimistic
    14.     If rsStocks.RecordCount <> 0 Then
    15.       txtSupply.Text = rsStocks.Fields("Quantity")
    16.       txtDesc.Text = rsStocks.Fields("ProductDescription")
    17.       'txtSellingPrice.Text = Format$(rsStocks.Fields("SellingPrice"), "P###,###,##0.00")
    18.     Else
    19.       txtSupply.Text = ""
    20.       txtDesc.Text = ""
    21.       'txtSellingPrice.Text = ""
    22.       txtSubTotal.Text = ""
    23.     End If
    24.  Else
    25.     txtSupply.Text = ""
    26.     txtDesc.Text = ""
    27.     'txtSellingPrice.Text = ""
    28.     txtSubTotal.Text = ""
    29.   End If
    30. End Sub
    31.  
    32.  
    33. Private Sub lstStocks_DblClick()
    34.   If lstStocks.ListItems.Count = 0 Then
    35.     Exit Sub
    36.   Else
    37.     edwin = lstStocks.SelectedItem.Index
    38.     txtCode.Text = lstStocks.ListItems.Item(edwin).Text
    39.     txtDiscount.Text = Val(lstStocks.ListItems.Item(edwin).SubItems(4)) '/ Val(lstStocks.ListItems.Item(edwin).SubItems(2))
    40.     txtQty.Text = lstStocks.ListItems.Item(edwin).SubItems(2)
    41.     txtSellingPrice.Text = Val(lstStocks.ListItems.Item(edwin).SubItems(3))
    42.     'iQtyTemp = txtQty.Text
    43.    
    44.     sSQL = "UPDATE tblStocks SET Quantity = Quantity + " & txtQty.Text & " WHERE [Code]= '" & (lstStocks.ListItems.Item(edwin).Text) & "'"
    45.     oConn.Execute sSQL
    46.     Debug.Print sSQL
    47.     Debug.Print rsStocks.Fields("quantity")
    48.     lstStocks.ListItems.Remove (edwin)
    49.     txtCode.Locked = True
    50.    
    51.     cAmountDueTemp = 0
    52.     For i = 1 To lstStocks.ListItems.Count
    53.       cAmountDueTemp = CCur(cAmountDueTemp) + CCur(lstStocks.ListItems.Item(i).SubItems(5))
    54.       txtAmountDue.Text = cAmountDueTemp
    55.     Next
    56.     lstStocks.Enabled = False
    57.   End If
    58. End Sub
    59.  
    60.  
    61. Private Sub cmdAddItem_Click()
    62.   Dim lst As ListItem, itemFound As ListItem
    63.  
    64.   If txtCode.Locked = True Then
    65.     txtCode.Locked = False
    66.   End If
    67.  
    68.   If lstStocks.Enabled = False Then
    69.     lstStocks.Enabled = True
    70.   End If
    71.  
    72.   'If rsStocks.State = adStateOpen Then rsStocks.Close
    73.   'rsStocks.Open "SELECT * FROM tblStocks WHERE Code = '" & txtCode.Text & "'", oConn, adOpenStatic, adLockOptimistic
    74.      
    75.   '=====================================================================
    76.   '= The above commented code is the same with the enclosed code below =
    77.   '=====================================================================
    78.   '####################################################################
    79.   sSQL = "SELECT * FROM tblStocks WHERE [Code] = '" & txtCode.Text & "'"
    80.  
    81.   If rsStocks.State = adStateOpen Then rsStocks.Close
    82.   rsStocks.Open sSQL, oConn, adOpenStatic, adLockOptimistic
    83.   '#####################################################################
    84.   If CheckNullValue = False Then Exit Sub
    85.   If Compare = False Then Exit Sub 'or If Not Compare Then Exit Sub
    86.  
    87.   If Val(txtQty.Text) > Val(txtSupply.Text) Then
    88.     Call msgSupply
    89.     txtQty.SetFocus
    90.     SendKeys "{home}+{end}"
    91.     Exit Sub
    92.   'End If
    93.  
    94.   ElseIf txtQty.Text <> 0 Then
    95.   'Set itemFound = lstStocks.FindItem(txtCode.Text)
    96.   'If itemFound Is Nothing Then
    97.     cAmountDueTemp = 0
    98.     If txtDiscount.Text = "" Then
    99.       txtDiscount.Text = 0
    100. '      cSubtotal = (val(txtQty.Text) * CCur(rsStocks.Fields("SellingPrice")))
    101.       cSubtotal = (Val(txtQty.Text) * Val(txtSellingPrice.Text))
    102.       cMargin = (Val(txtSellingPrice.Text) * Val(txtQty.Text)) - (rsStocks.Fields("PurchasePrice") * Val(txtQty.Text))
    103.     Else
    104.       'iTempSubTotal = (Val(txtQty.Text) * Val(rsStocks.Fields("SellingPrice"))) - (Val(txtQty.Text) * (Val(txtDiscount.Text)))
    105. '      cSubtotal = (val(txtQty.Text) * val(rsStocks.Fields("SellingPrice"))) - (Val(txtQty.Text) * (val(txtDiscount.Text))) 'Val(iTempSubTotal))
    106.       cSubtotal = (Val(txtQty.Text) * Val(txtSellingPrice.Text)) - (Val(txtQty.Text) * (Val(txtDiscount.Text))) 'Val(iTempSubTotal))
    107.       cMargin = (Val(txtSellingPrice.Text) * Val(txtQty.Text)) - Val(txtQty.Text) * Val(txtDiscount.Text) - (rsStocks.Fields("PurchasePrice") * Val(txtQty.Text))
    108.     End If
    109.  
    110.     'rsStocks.Fields("Quantity") = (Val(rsStocks.Fields("Quantity") + Val(iQtyTemp)) - Val(txtQty.Text))
    111.     'rsStocks.Update 'Update the database
    112.    
    113.     'Check if it's time to order the item
    114.     If rsStocks.Fields("Quantity") <= rsStocks.Fields("ReOrder") Then
    115.       MsgBox rsStocks.Fields("ProductDescription") & " Product" & _
    116.       Chr(13) & "has reached its Re-order Point", vbInformation, ProgName
    117.       txtQty.SetFocus
    118.     End If
    119.  
    120. '    sSQL = "UPDATE TblStocks SET Quantity = Quantity + " & iQtyTemp & " - " & Val(txtQty.Text) & " WHERE [Code]='" & txtCode.Text & "'"
    121.     sSQL = "UPDATE TblStocks SET Quantity = Quantity  - " & Val(txtQty.Text) & " WHERE [Code]='" & txtCode.Text & "'"
    122.     oConn.Execute sSQL
    123.    
    124.     Set lst = lstStocks.ListItems.Add(, , txtCode.Text) 'DISPLY IN LISTVIEW
    125.       lst.SubItems(1) = txtDesc.Text
    126.       lst.SubItems(2) = txtQty.Text
    127. '      lst.SubItems(3) = Format$(rsStocks.Fields("SellingPrice"), "###,###,##0.00")
    128.       lst.SubItems(3) = Format$(Val(txtSellingPrice.Text), "###,###,##0.00")
    129.       lst.SubItems(4) = Format$(Val(txtDiscount.Text), "###,###,##0.00")
    130.       lst.SubItems(5) = Format$(CCur(cSubtotal), "###,###,##0.00")
    131.       lst.SubItems(6) = Format$(rsStocks.Fields("PurchasePrice"), "###,###,##0.00")
    132.       lst.SubItems(7) = Format$(CCur(cMargin))
    133.    
    134.     txtCode.Text = ""
    135.     txtDiscount.Text = ""
    136.     txtQty.Text = ""
    137.     txtSellingPrice.Text = ""
    138.     txtCode.SetFocus
    139.  
    140.     For i = 1 To lstStocks.ListItems.Count
    141.       cAmountDueTemp = CCur(cAmountDueTemp) + CCur(lstStocks.ListItems.Item(i).SubItems(5))
    142.       txtAmountDue.Text = Format$(cAmountDueTemp, "###,###,##0.00")
    143.     Next
    144.   Else
    145.     MsgBox "Quantity must not be zero", vbInformation, ProgName
    146.     txtQty.SetFocus
    147.     SendKeys "{home}+{end}"
    148.   End If
    149.  
    150.   Set lst = Nothing 'destroy the list
    151.  
    152. '  Else
    153. '    MsgBox "Product code already exists in the list.", vbInformation
    154. '    txtCode.Text = ""
    155. '    txtDiscount.Text = ""
    156. '    txtQty.Text = ""
    157. '  End If
    158.  
    159. End Sub
    Last edited by Simply Me; Jul 27th, 2006 at 09:38 AM.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

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