Dim imagefile As String
Private Sub CommandButton1_Click()
imagefile = Application.GetOpenFilename(Title:="Select Image", _
FileFilter:="ImageFiles(*.png;*.Jpeg;*.JpG), *.png;*.Jpeg;*.JpG")
If imagefile = "False" Then
MsgBox "Please Select one Image"
Else
Me.Image1.Picture = LoadPicture(imagefile)
Me.Image1.PictureSizeMode = fmPictureSizeModeStretch
End If
End Sub
Private Sub CommandButton2_Click()
Dim sheet_v As Worksheet
Set sheet_v = ThisWorkbook.Sheets("Sheet1")
Dim last_row As Integer
last_row = sheet_v.Range("A" & Rows.Count).End(xlUp).Row
sheet_v.Range("A" & last_row + 1).Value = Me.code_student.Value
sheet_v.Range("b" & last_row + 1).Value = Me.name_txt.Value
sheet_v.Range("C" & last_row + 1).Value = Me.age_txt.Value
sheet_v.Range("D" & last_row + 1).Value = imagefile
MsgBox "The student inserted Successfully"
End Sub
Private Sub CommandButton3_Click()
Me.code_student.Value = ""
Me.name_txt.Value = ""
Me.age_txt.Value = ""
imagefile = ""
Me.Image1.Picture = LoadPicture(imagefile)
End Sub
Private Sub CommandButton4_Click()
If Me.search_txt.Text = "" Then
MsgBox "Please Enter code student"
Else
Dim sheet_v As Worksheet
Set sheet_v = ThisWorkbook.Sheets("Sheet1")
Dim last_row, i As Integer
last_row = sheet_v.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To last_row
If Me.search_txt.Text = sheet_v.Cells(i, 1) Then
Me.code_student.Text = sheet_v.Cells(i, 1)
Me.name_txt.Value = sheet_v.Cells(i, 2)
Me.age_txt.Value = sheet_v.Cells(i, 3)
imagefile = sheet_v.Cells(i, 4)
Me.Image1.Picture = LoadPicture(imagefile)
Me.Image1.PictureSizeMode = fmPictureSizeModeStretch
Exit Sub
Else
Me.code_student.Value = ""
Me.name_txt.Value = ""
Me.age_txt.Value = ""
imagefile = ""
Me.Image1.Picture = LoadPicture(imagefile)
End If
Next i
End If
End Sub
Private Sub CommandButton5_Click()
Dim sheet_v As Worksheet
Set sheet_v = ThisWorkbook.Sheets("Sheet1")
Dim last_row, i As Integer
last_row = sheet_v.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To last_row
If Me.search_txt.Text = sheet_v.Cells(i, 1) Then
sheet_v.Cells(i, 1) = Me.code_student.Text
sheet_v.Cells(i, 2) = Me.name_txt.Value
sheet_v.Cells(i, 3) = Me.age_txt.Value
sheet_v.Cells(i, 4) = imagefile
Me.Image1.Picture = LoadPicture(imagefile)
Me.Image1.PictureSizeMode = fmPictureSizeModeStretch
End If
Next i
End Sub
Private Sub CommandButton6_Click()
Dim sheet_v As Worksheet
Set sheet_v = ThisWorkbook.Sheets("Sheet1")
Dim last_row, i As Integer
last_row = sheet_v.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To last_row
If Me.search_txt.Text = sheet_v.Cells(i, 1) Then
Rows(i).Delete
End If
Next i
Me.code_student.Value = ""
Me.name_txt.Value = ""
Me.age_txt.Value = ""
imagefile = ""
Me.Image1.Picture = LoadPicture(imagefile)
End Sub
Private Sub UserForm_Click()
End Sub