MohamedAmin
New Member
- Joined
- May 17, 2023
- Messages
- 21
- Office Version
- 2021
- Platform
- Windows
VBA Code:
Private Sub CmdAddItem_Click() 'add item
ThisWorkbook.Activate
'====check product list =====
If Me.CbProductList.MatchFound = False Then: MsgBox "Data Error : Please select of items list ", vbCritical, "Inventory Program ": Me.CbProductList.SetFocus: Exit Sub
'===== check q as number====
If Not IsNumeric(Me.TbQuantity.Value) Then: MsgBox "Data Error: not have quantity: Please enter the quantity ", vbCritical, "Inventory Program": Me.TbQuantity.SetFocus: Exit Sub
'====== check raseed =======
If Not Me.CbInvStore.Value = Data.Range("BF7") Then GoTo 11
If Val(Me.TbQuantity.Value) + Val(Me.TbShipQuantity.Value) > Val(Me.TbRaseedNow.Value) Then
confir = MsgBox(" Quantity available is not sufficient warehouse for sale. please check inventory " & vbCrLf & "Do you want to continue ?", _
vbYesNo + vbMsgBoxLeft, "Inventory Programs ")
If confir = vbNo Then: Me.TbQuantity.Value = "": Me.TbQuantity.SetFocus: Exit Sub
End If
'===========================
11 np = Val(Me.TbNetPrice.Value) * Val(Me.TbQuantity.Value) * (Val(Me.TbMohDiscount.Value) / 100)
'On Error Resume Next
With ListBox1
Dim i As Integer
Dim b
i = .ListCount
.AddItem i
.List(i, 0) = Me.TbCode.Value
.List(i, 1) = Me.CbProductList.Value
.List(i, 2) = Me.TbProductType.Value
.List(i, 3) = Me.TbQuantity.Value
.List(i, 4) = Format(Me.TbNetPrice.Value, "0.00")
.List(i, 5) = Val(Me.TbQuantity.Value) * Val(Me.TbNetPrice.Value)
.List(i, 7) = Val(Me.TbQuantity.Value) * Val(Me.TbShipQuantity.Value)
.List(i, 8) = Me.TbProductPrice.Value
If Me.CbInvStore = "Purchase" Then
.List(i, 8) = Val(Me.TbNetPrice.Value) + Val(Me.TbShipQuantity.Value)
End If
If Not IsNumeric(Me.TbMohDiscount.Value) Then GoTo 1
.List(i, 6) = Format(Me.TbMohDiscount.Value / 100, "0.00%")
'b = 1 + (Me.TbMohDiscount / 100)
1 If b <= 0 Or b = Empty Then
.List(i, 9) = np
Else
.List(i, 9) = np / b
End If
.List(i, 9) = Val(.List(i, 5)) - np + Val(.List(i, 7))
If Me.CbInvStore = "Sales" Then
.List(i, 10) = Me.TbProductPrice.Value * Me.TbQuantity.Value '(Here is the Mismatch )
.List(i, 11) = Val(.List(i, 9)) - np - Val(.List(i, 10))
End If
.List(i, 4) = Format(.List(i, 4), "$#,##0.00")
.List(i, 5) = Format(.List(i, 5), "$#,##0.00")
.List(i, 7) = Format(.List(i, 7), "$#,##0.00")
.List(i, 8) = Format(.List(i, 8), "$#,##0.00")
.List(i, 9) = Format(.List(i, 9), "$#,##0.00") 'net price
.List(i, 10) = Format(.List(i, 10), "$#,##0.00")
.List(i, 11) = Format(.List(i, 11), "$#,##0.00")
'.List(i, 10) = Val(.List(i, 3)) * Val(.List(i, 9)) 'q only * net price = total net price
'.List(i, 11) = Val(.List(i, 8)) * Val(Me.TbNetPrice.Value) 'all q+b * net price = total puplic price
'.List(i, 10) = Format(.List(i, 10), "#,##0.00")
'.List(i, 11) = Format(.List(i, 11), "#,##0.00")
.Selected(1) = True
End With
'For Total
Dim sum As Double
For Row = 1 To ListBox1.ListCount - 1
sum = sum + ListBox1.List(Row, 9) (Here is the Mismatch )
Next Row
Me.TbTotalNetPrice = sum
Me.TbTotalNetPrice = Format(Me.TbTotalNetPrice, "$#,##0.00")
'For Cost
If Me.CbInvStore = "Sales" Then
Dim sumc As Double
For Row = 1 To ListBox1.ListCount - 1
sumc = sumc + ListBox1.List(Row, 10) '(Here is the Mismatch )
Next Row
Me.TbInvoCost = sumc
Me.TbInvoCost = Format(Me.TbInvoCost, "$#,##0.00")
'For Profit
Dim sump As Double
For Row = 1 To ListBox1.ListCount - 1
sump = sump + ListBox1.List(Row, 11) ' (Here is the Mismatch )
Next Row
Me.TbProfit = sump
Me.TbProfit = Format(Me.TbProfit, "$#,##0.00")
Me.TbProfit = Format(sum - sumc, "$#,##0.00")
End If
Me.TbCode = ""
Me.TbQuantity = ""
Me.TbBonusNet = ""
Me.TbBonusPercent = ""
Set TotalS = Profit.Range("Q8")
Me.TotalSales = Format(TotalS.Value + Me.TbTotalNetPrice.Value, "$#,##0.00")
Set Totalc = Profit.Range("R8")
Me.TotalCost = Format(Totalc.Value + Me.TbInvoCost.Value, "$#,##0.00")
Set Totalp = Profit.Range("S8")
Me.TotalProfit = Format(Totalp.Value + Me.TbProfit.Value, "$#,##0.00")
Me.LbPercentage.Value = Format(TotalProfit.Value / TotalSales.Value, "0.00%")
Me.TbCode.SetFocus
End Sub