Banner

Thursday, October 26, 2017

Create Regestry Form for Employee Support Excel VBA





Code Userform1

Step1
Private Sub UserForm_Initialize()
a = Application.WorksheetFunction.CountA(Sheet2.Range("A:A"))
Me.TextBox1 = a + 1000
Me.TextBox2.SetFocus
End Sub


Step2
Private Sub OptionButton1_Click()
Me.TextBox7 = "Male"
Me.TextBox3.SetFocus
End Sub

Private Sub OptionButton2_Click()
Me.TextBox7 = "Female"
Me.TextBox3.SetFocus
End Sub

Step3
Private Sub CommandButton1_Click()
a = Application.GetSaveAsFilename()
Me.TextBox6 = a
Me.Image1.Picture = LoadPicture(Me.TextBox6)
End Sub

Step4
Private Sub CommandButton2_Click()
Dim i As Long
i = Application.WorksheetFunction.CountA(Sheet2.Range("A:A"))
If Me.TextBox1 = "" Or Me.TextBox2 = "" Then
MsgBox "Please Input Name & Contact"
Else
For X = 1 To 7
Sheet2.Range("A" & i).End(xlToLeft).Offset(1, X - 1) = Me("textbox" & X)
Next X
End If
Unload Me
UserForm1.Show
End Sub

Code Userform2

Step1
Private Sub UserForm_Initialize()
Me.TextBox7.SetFocus
End Sub

Step2
Private Sub CommandButton1_Click()
Dim i As Long
For i = 2 To Application.WorksheetFunction.CountA(Sheet2.Range("A:A"))
If Sheet2.Cells(i, 1) = Val(Me.TextBox7) Then
For X = 1 To 4
Me("textbox" & X) = Sheet2.Cells(i, X + 1)
Next X
Me.TextBox5 = Sheet2.Cells(i, "G")
Me.Image1.Picture = LoadPicture(Sheet2.Cells(i, "F"))
End If
Next i
End Sub

2 comments:

  1. Very good and excellent form. Thank you

    ReplyDelete
  2. Hello,I have a question
    If I put an id number but this number not registered. What code to get msgbox inform me that the id number don't exist.
    Thank you

    ReplyDelete

Please do not enter any spam message in comment box