
Originally Posted by
pyol17
Actually i also want to ask for the code to update the inventory.
Different method including "Update functionality"
Option Explicit
Private dic As Object
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
Me.Label4.Caption = ""
If Len(.Value) Then
If dic.exists(.Value) Then
Me.Label4.Caption = dic(.Value).Value
Me.CommandButton2.Enabled = True
Else
Me.Label4.Caption = "Not available"
End If
End If
Me.CommandButton2.Enabled = Len(.Value)
End With
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
With Sheets("sheet1").Range("c8").CurrentRegion
For i = 2 To .Rows.Count
Set dic(.Cells(i, 1).Value) = .Cells(i, 7)
Next
End With
Me.CommandButton2.Enabled = False
End Sub
Private Sub CommandButton2_Click()
Dim temp As Double
With Me
If dic.exists(.TextBox1.Value) Then
If (Me.OptionButton1) + (Me.OptionButton2) Then
temp = dic(Me.TextBox1.Value).Value _
+ (Val(.TextBox3.Value) * IIf(.OptionButton1, 1, -1))
If temp < 0 Then
MsgBox "Short in stock by " & Abs(temp), , .TextBox1.Value
Else
dic(.TextBox1.Value).Value = temp
.Label4.Caption = temp
End If
End If
Else
MsgBox .TextBox1.Value & " is not available"
End If
End With
End Sub
Bookmarks