I want this code to add value to all table, (Code, item name, unit, price)
Private Sub cmdAdd_Click()
Const PW As String = "8521" 'using const for fixed values
Dim allTables(), lo As ListObject, rw As ListRow, tName
allTables = Array("T_Food", "T_Beverage", "T_Shisha")
If Me.comDepartment.Text = "" Or Me.txtItemName.Text = "" Or _
Me.txtPrice.Text = "" Or Me.comUnit.Text = "" Then
MsgBox "Please enter data ", vbCritical, "Inventory program "
Exit Sub
End If
new_name = Me.txtItemName.Text
'see if the new name already exists in any of the tables
If Not AnyTableRowMatch(allTables, "Item Name", new_name) Is Nothing Then
MsgBox "The new name '" & new_name & "' already exists ", _
vbCritical, "Inventory Program "
Exit Sub
End If
'select the correct table
Select Case Me.comDepartment.Value
Case "Food": tName = "T_Food"
Case "Beverage": tName = "T_Beverage"
Case "Shisha": tName = "T_Shisha"
Case "Other": tName = "T_Other"
End Select
'find the record being edited
Set rw = TableRowMatch(Data.ListObjects(tName), "Item Name, new_name")
If Not rw Is Nothing Then
Data.Unprotect PW
'update the row
'-----------------------------------------------------
' update the row values (but I don't know where Start and Price come from)
rw.Range.Value = Array(Me.txtCode.Text, new_name, Me.comUnit.Text, _
Me.txtPrice.Text, Me.TxtSalePrice.Text, _
"", "", Me.CbSubCategory.Text)
'-----------------------------------------------------
Data.Protect Password:=PW
Else
MsgBox "Edited row not found!"
End If
' update the userfrom
Call CbSubCategory_Change
End Sub