Tuesday, March 10, 2020

BELAJAR USERFORM INPUT DATA DAN FOTO



Buatlah sebuah Userform yang terdiri dari 2 CommandButton
satu untuk tombol input data dan satu lagi untuk input foto
yang mana tombol kedua akan disembunyikan namun akan dipanggil otomatis ketika tombol input di klik


Pastekan kode berikut pada CommandButton1

Private Sub CommandButton1_Click()
With ActiveSheet
Dim irow As Long
'Deklarasi  irow  input atau mengisi  baris terakhir pada sheet1
irow = Cells(Rows.Count, 2).End(xlUp).Offset(1, 2).Row
Cells(irow, 2).Value = TextBox1.Value
Cells(irow, 3).Value = TextBox2.Value
Cells(irow, 4).Value = TextBox3.Value
Cells(irow, 5).Value = TextBox4.Value
End With
CommandButton2_Click
End With
End Sub

Pastekan kode berikut pada CommandButton 2

Private Sub CommandButton2_Click()
 If TextBox1.Value = "" Then
 MsgBox "Maaf Nama Foto Belum diisi", vbCritical
 Else
   On Error Resume Next
    Dim Filter As String, Title As String, FileIROW As String
    Dim SourceFile, DestinationFile
    irow.SetFocus
    Filter = "jpg Images File Only(*.jpg),*.jpg,"
    FileIROW = Application.GetOpenFilename(Filter, , Title)

    NamaFile = TextBox1.Value
    ActiveWorkbook.Image1.Picture = LoadPicture(FileIROW)
    Image1.Picture = LoadPicture(FileIROW)
    DestinationFile = ActiveWorkbook.Path & "\FOTO\" & NamaFile & ".jpg"
    FileCopy FileIROW, DestinationFile
    End If
        End Sub

Pastekan kode berikut pada Userform

Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 4
ListBox1.ColumnWidths = 35 & ";" & 100 & ";" & 100 & ";" & 80
ListBox1.RowSource = "data"
Label2.Caption = Cells(5, 2).Value
Label3.Caption = Cells(5, 3).Value
Label4.Caption = Cells(5, 4).Value
Label5.Caption = Cells(5, 5).Value
End Sub


Halaman berikutnya >>>>  userform tampilkan data

No comments:

Post a Comment

APLIKASI GUDANG VERSI EXCEL VBA

Aplikasi Gudang Sederhana silahkan dikembangkan kritik dan saran membangun selalu kami harapkan FROM ENTRI IURAN BULANA...