Selected Answer
Amin
It seems your question was referring to the Userform "frmCodeItem".(please say so next time!).
In the attached revoised file, I've chnaged your UserForm code as as follows:
To get the item number (for the last item in the LB_)1 list, if any) showing, I modified this code, as shown in bold:
Private Sub CbSubCategory_Change()
<< existing code>>
End If
' show the item number for the last item in list (if any)
If s > 0 Then Me.txtCode.Value = Me.LB_01.List(s - 1, 0)
End Sub
Also, when the Depatment is changed, the current code left theUserform showing selections from the old subcategory (so items NOT in the new Department). I changed this code as follows (in bold):
Private Sub comDepartment_Change()
<< existing code>>
End If
' clear the SubCategory and other boxes to allow new selection
Me.CbSubCategory = ""
Me.txtItemName = ""
Me.txtPrice = ""
Me.TxtSalePrice = ""
Me.comUnit = ""
Me.LB_01.RowSource = ""
End Sub
Hope this fixes your problem. If so, please be sure to mark this Answer as Selected.