You are on page 1of 3

command button 1 = add photo

command button 2 = Add Data & Save Photo


command button 3 = Reset Form
command button 4 = Close form
command button 5 = Search Data
command button 6 = Update Data
command button 7 = Delete Data

Dim fpath As String


Private Sub CommandButton1_Click()
Dim x As Integer
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
x = Application.FileDialog(msoFileDialogOpen).Show
If x <> 0 Then
fpath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
Image1.Picture = LoadPicture(fpath)
Image1.PictureSizeMode = 1
End If
End Sub
Private Sub CommandButton2_Click()
Dim x As Long
Dim y As Worksheet
Set y = Sheet3
x = y.Range("A" & Rows.Count).End(xlUp).Row
With y
.Cells(x + 1, "A").Value = TextBox1.Text
.Cells(x + 1, "B").Value = TextBox2.Text
End With
On Error Resume Next
Dim i As String
i = TextBox1.Text
FileCopy fpath, "C:\Photo\" & i & ".jpg"
Me.TextBox1.Text = ""
End Sub
Private Sub CommandButton3_Click()
Unload Me
UserForm2.Show
End Sub
Private Sub CommandButton4_Click()
Unload Me
End Sub
Private Sub CommandButton5_Click()
Dim x As Long
Dim y As Long
x = Sheet3.Range("A" & Rows.Count).End(xlUp).Row
For y = 2 To x
If Sheet3.Cells(y, "A").Text = TextBox3.Text Then
TextBox1.Text = Sheet3.Cells(y, "a")
TextBox2.Text = Sheet3.Cells(y, "b")
End If
Next y
End Sub

Private Sub CommandButton6_Click()


Dim x As Long
Dim y As Long
x = Sheet3.Range("A" & Rows.Count).End(xlUp).Row
For y = 2 To x
If Sheet3.Cells(y, "A").Text = TextBox3.Text Then
Sheet3.Cells(y, "a") = TextBox1.Text
Sheet3.Cells(y, "b") = TextBox2.Text
End If
Next y
End Sub
Private Sub CommandButton7_Click()
Dim x As Long
Dim y As Long
x = Sheet3.Range("A" & Rows.Count).End(xlUp).Row
For y = 2 To x
If Sheet3.Cells(y, "A").Text = TextBox3.Text Then
Rows(y).Delete shift:=xlUp
End If
Next y
End Sub
Private Sub TextBox2_Change()
TextBox2.Text = Application.WorksheetFunction.Proper(TextBox2.Text)
End Sub
Private Sub UserForm_Initialize()
TextBox1 = Application.WorksheetFunction.Max(Sheet3.Range("A6:a1000")) + 1
End Sub
Show Data in Form VBA code for Button
Dim x As Long
Dim y As Long
x = Sheet3.Range("A" & Rows.Count).End(xlUp).Row
For y = 2 To x
If Sheet2.Range("o3").Value = Sheet3.Cells(y, "a").Value Then
Sheet2.Range("e9").Value = Sheet3.Cells(y, "a").Value
Sheet2.Range("e10").Value = Sheet3.Cells(y, "B").Value
End If
Next y

Dim i As Picture
Dim j As String
On Error Resume Next
If target.Address = Range("o3").Address Then
ActiveSheet.Pictures.Delete
j = "c:\Photo\" & Range("o3") & Value & ".jpg"
With Range("j9")
Set i = ActiveSheet.Pictures.Insert(j)
i.Height = 98
i.Width = 95
i.Top = .Top
i.Left = .Left
i.Placement = xlMoveAndSize
End With
End If

You might also like