Results 1 to 40 of 98

Thread: Sql Count

Threaded View

  1. #1

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

    Sql Count

    Hello everybody! My code below will INSERT records in my two tables namely "tblStockMasterFile and tblStockFile". When the Save button is clicked it checks whether a product ID entered already exists or not. If product exists then the records will be save in tblStocktransFile Only otherwise to both tables. I attached the table for reference.

    Code:
    Private Sub cmdSave_Click()
      If CheckNullValue = False Then Exit Sub
      Call ReplaceQuotation(txtProdName)
    
    On Error GoTo ErrHandler
      If Checker = True Then  'Product ID already Exist then save in tblStocktransFile Only
        
        sSQL = "INSERT INTO tblStockTransFile (ProductID, EntryDate, PurchasePrice, Quantity, Reason,Sequence)" & _
                  "VALUES('" & txtProdID.Text & "','" & txtEntryDate.Text & "','" & txtProdPurchasePrice.Text & _
                       "','" & txtProdQTY.Text & " ','" & txtReason.Text & "','" & txtSEQ.Text & "')"
                     '  Debug.Print sSQL
        oConn.Execute sSQL
      
      Else  'Product ID does not Exist so save in both tblStockMasterFile and tblStockTransFile
        
        oConn.BeginTrans
          
            sSQL = "INSERT INTO tblStockMasterFile(ProductID, ProductName,Unit,ReOrderPoint)" & _
                  "VALUES( '" & txtProdID.Text & "','" & txtProdName.Text & "','" & txtProdUnit.Text & " ', '" & txtProdReOrderPoint.Text & "')"
          oConn.Execute sSQL
      
            sSQL = "INSERT INTO tblStockTransFile (ProductID, EntryDate, PurchasePrice, Quantity, Reason,Sequence)" & _
                  "VALUES('" & txtProdID.Text & "','" & txtEntryDate.Text & "','" & txtProdPurchasePrice.Text & _
                       "','" & txtProdQTY.Text & " ','" & txtReason.Text & "','" & txtSEQ.Text & "')"
                     '  Debug.Print sSQL
          oConn.Execute sSQL
    
        oConn.CommitTrans
        
      End If
      
      Call FillListView(lstStockMasterFile, rsStock)
      Call ClearFunction(frmStockMasterFile, "TextBox")
    
      txtProdID.SetFocus
      Exit Sub
    
    ErrHandler:
      Call msgError(Err)
    End Sub 'cmdSave_Click
    I would like instead of checking the ProductID only, I would also like to check the entry date and if the date already exists for the same product ID i would like to the program to increment the existing sequence value i have in my tblStockTransFile so that there's no need for the user to remember the last sequence value for each of the products and manually type it.
    Code:
    For example:
    productID: 01
    ProductName: Colgate
    Unit: Tube
    PurchasePrice: 30.00
    Quantity:100
    Reason: In --->StockIn
    EntryDate: 9/15/07
    ReOrderPoint: 10
    Sequence: 1
    If I add more stock to the product the program should look into the sequence value and add 1 to it.

    Below is function checker. It lacks the entrycode and I dont know how or what should i add to it. Can someone please help me out please?
    Code:
    'TODO : return true if ProductID already exist
    Private Function Checker() As Boolean
      Checker = False
    
      If rsTempStock.State = adStateOpen Then rsTempStock.Close
      sSQL1 = "SELECT COUNT(ProductID) as ProductIDExist " & _
             "FROM tblStockMasterFile " & _
             "WHERE ProductID = '" & (txtProdID.Text) & "'"
      'Debug.Print sSQL1
      rsTempStock.Open sSQL1, oConn, adOpenKeyset, adLockReadOnly
    
      If rsTempStock("ProductIDExist") > 0 Then Checker = True
    End Function  'Function Checker
    I am thinking of adding another check function for the date like the code below but I guess it's not how it is done.
    Code:
    'TODO : return true if Date already exist
    Private Function DateChecker() As Boolean
      DateChecker = False
    
      If rsTempStock.State = adStateOpen Then rsTempStock.Close
      sSQL1 = "SELECT COUNT(EntryDate) as DateExist " & _
             "FROM tblStockTransFile " & _
             "WHERE EntryDate = '" & (txtEntryDate.Text) & "'"
      'Debug.Print sSQL1
      rsTempStock.Open sSQL1, oConn, adOpenKeyset, adLockReadOnly
    
      If rsTempStock("DateExist") > 0 Then Checker = True
    End Function  'Function DateChecker
    Attached Images Attached Images  
    Last edited by Simply Me; Sep 15th, 2007 at 05:16 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