Sam,
Try this.
On your userform (Userform1), add four text boxes:
tbStudID, tbName, tbAddress, and tbPh_No
Then add 2 commandbuttons
cbFindData
cbAddDataToDB
Add the code below to the codemodule of the userform. And use this code to show it:
Sub ShowIDForm()
Load UserForm1
UserForm1.Show
End Sub
I've assumed that you Student IDs are in column A, Names in column B, Addresses in column C, and
phone #s in column D, all on the only sheet of the workbook.
HTH,
Bernie
MS Excel MVP
Option Explicit
Dim ICnt As Integer
Dim myR As Long
Private Sub cbFindData_Click()
Me.tbName.Text = ""
Me.tbAddress.Text = ""
Me.tbPh_No.Text = ""
ICnt = ICnt + 1
If Not IsError(Application.Match(tbStudID.Text, Range("A:A"), False)) Then
myR = Application.Match(tbStudID.Text, Range("A:A"), False)
Me.tbName.Text = Cells(myR, 2).Value
Me.tbAddress.Text = Cells(myR, 3).Value
Me.tbPh_No.Text = Cells(myR, 4).Value
ICnt = 0
End If
If Me.tbName.Value = "" Then
If ICnt < 3 Then
MsgBox ("Please re-enter Student Id number")
Exit Sub
Else
MsgBox "Please enter information into boxes"
End If
Me.tbName.Enabled = True
Me.tbAddress.Enabled = True
Me.tbPh_No.Enabled = True
Me.cbAddDataToDB.Enabled = True
End If
End Sub
Private Sub cbAddDataToDB_Click()
If Me.tbStudID.Text <> "" And _
Me.tbName.Text <> "" And _
Me.tbAddress.Text <> "" And _
Me.tbPh_No.Text <> "" Then
myR = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(myR, 1).Value = Me.tbStudID.Text
Cells(myR, 2).Value = Me.tbName.Text
Cells(myR, 3).Value = Me.tbAddress.Text
Cells(myR, 4).Value = Me.tbPh_No.Text
ICnt = 0
Else
MsgBox "Fill it all in"
End If
End Sub
Private Sub UserForm_Activate()
Me.cbAddDataToDB.Enabled = False
Me.tbName.Enabled = False
Me.tbAddress.Enabled = False
Me.tbPh_No.Enabled = False
ICnt = 0
End Sub