You are on page 1of 2

Option Explicit Private Sub cmdAdd_Click() Dim lRow As Long Dim lPart As Long Dim ws As Worksheet Set ws = Worksheets("PartsData")

'find first empty row in database lRow = ws.Cells(Rows.Count, 1) _ .End(xlUp).Offset(1, 0).Row lPart = Me.cboPart.ListIndex 'check for a part number If Trim(Me.cboPart.Value) = "" Then Me.cboPart.SetFocus MsgBox "Please enter a part number" Exit Sub End If 'copy the data With ws .Cells(lRow, .Cells(lRow, .Cells(lRow, .Cells(lRow, .Cells(lRow, End With to the database 1).Value 2).Value 3).Value 4).Value 5).Value = = = = = Me.cboPart.Value Me.cboPart.List(lPart, 1) Me.cboLocation.Value Me.txtDate.Value Me.txtQty.Value

'clear the data Me.cboPart.Value = "" Me.cboLocation.Value = "" Me.txtDate.Value = Format(Date, "Medium Date") Me.txtQty.Value = 1 Me.cboPart.SetFocus End Sub Private Sub cmdClose_Click() Unload Me End Sub Private Sub UserForm_Initialize() Dim cPart As Range Dim cLoc As Range Dim ws As Worksheet Set ws = Worksheets("LookupLists") For Each cPart In ws.Range("PartIDList") With Me.cboPart .AddItem cPart.Value .List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value End With Next cPart For Each cLoc In ws.Range("LocationList") With Me.cboLocation .AddItem cLoc.Value End With

Next cLoc Me.txtDate.Value = Format(Date, "Medium Date") Me.txtQty.Value = 1 Me.cboPart.SetFocus End Sub

You might also like