The code for the 'AddData' command button is also given here for your ready reference:
Dim eRow As Long
Dim ws As Worksheet
Set ws = Worksheets("data")
'find first empty row in database
eRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'check for a name
If Trim(Me.txtName.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter a name"
Exit Sub
End If
'copy the data to the database
ws.Cells(eRow, 1).Value = Me.txtName.Value
ws.Cells(eRow, 2).Value = Me.txtSalary.Value
ws.Cells(eRow, 3).Value = Me.txtHRA.Value
ws.Cells(eRow, 4).Value = Me.txtPF.Value
ws.Cells(eRow,5).Value=Me.txtMed.Value
ws.Cells(eRow,6).Value=Me.txtPkg.Value
'clear the data
Me.txtName.Value = ""
Me.txtSalary.Value = ""
Me.txtHRA.Value = ""
Me.txtPF.Value = ""
Me.txtMed.Value=""
Me.txtPkg.Value = ""
Me.txtName.SetFocus
|