Creating User Form For Contact Details Entry

Creating User Form For Contact Details Entry


Private Sub CommandButton1_Click()

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

'check for a Name
If Trim(Me.TextBoName.Value) = "" Then
  Me.TextBoName.SetFocus
  MsgBox "Please enter a Name"
  Exit Sub
End If

'copy the data to the database
'use protect and unprotect lines,
'     with your password
'     if worksheet is protected
With ws
'  .Unprotect Password:="password"
  .Cells(iRow, 1).Value = Me.TextBoName.Value
  .Cells(iRow, 2).Value = Me.TextBoxEmail.Value
  .Cells(iRow, 3).Value = Me.TextBoxMob.Value
  .Cells(iRow, 4).Value = Me.TextBoxAdd.Value
'  .Protect Password:="password"



End With


MsgBox "Data Successfully Insrted"
End Sub

Private Sub CommandButton2_Click()

Me.TextBoName.Text = ""
Me.TextBoxEmail.Text = ""
Me.TextBoxMob.Text = ""
Me.TextBoxAdd.Text = ""

End Sub

Private Sub UserForm_Initialize()

Range("A1").Value = "Name"
Range("B1").Value = "Email ID"
Range("C1").Value = "Mobile No"
Range("D1").Value = "Address"
End Sub


Post a Comment

Previous Post Next Post