Membuat Program Simpan Update Hapus Foto

Tanpa Pengantar langsung Saja CopyPaste Code Berikut:
Module1:

Public conn As New ADODB.Connection
Public RSdata As New ADODB.Recordset
Sub koneksi()
Set conn = New ADODB.Connection
Set RSdata = New ADODB.Recordset
conn.Open "Provider=microsoft.jet.oledb.4.0;data source = " & App.Path & "\DBKOLEKSI.mdb"
conn.CursorLocation = adUseClient
End Sub

Form1:

Private Sub CMDBERSIH_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text1.SetFocus
End Sub

Private Sub CMDCARI_Click()
CommonDialog1.ShowOpen
Text4 = CommonDialog1.FileName
End Sub

Private Sub CMDEDIT_Click()
Dim SQLEdit As String
Call simpan
SQLEdit = "Update t_data Set nama= '" & Text2 & "'," & " ALAMAT='" & Text3 & "' where nrp='" & Text1 & "'"
conn.Execute SQLEdit
MsgBox " DATA BERHASIL DI-UPDATE"
Form_Activate
End Sub
Private Sub CMDHAPUS_Click()
Dim X As String
X = MsgBox(("Anda yakin data ini mau dihapus?"), vbYesNo + vbCritical)
If X = vbYes Then
'Hapus Record
    Adodc1.Recordset.Delete
    Adodc1.Recordset.MoveFirst
    DataGrid1.ReBind
    DataGrid1.Refresh
    Kill (App.Path & "\foto\NRP_" & Text1.Text & ".jpg")
    MsgBox "foto telah dihapus!", vbInformation + vbOKOnly = vbIgnore
    Form_Activate
End If
End Sub

Private Sub CMDKELUAR_Click()
Unload Me
End Sub

Private Sub CMDSIMPAN_Click()
Dim SQLTambah As String
Call simpan
SQLTambah = "Insert Into t_data (nrp,nama,ALAMAT) values ('" & Text1 & "','" & Text2 & "','" & Text3 & "')"
conn.Execute SQLTambah
Form_Activate
End Sub

Private Sub DataGrid1_Click()
If Adodc1.Recordset.RecordCount <= 0 Then Exit Sub
    If Not Adodc1.Recordset.BOF And Not Adodc1.Recordset.EOF Then
        Text1.Text = Adodc1.Recordset.Fields("NRP")
        Text2.Text = Adodc1.Recordset.Fields("Nama")
        Text3.Text = Adodc1.Recordset.Fields("ALAMAT")
        Text4.Text = App.Path & "\foto\NRP_" & Text1.Text & ".jpg"
        Image1.Picture = LoadPicture(App.Path & "\foto\NRP_" & Text1.Text & ".jpg")
    End If
End Sub

Private Sub Form_Activate()
' perintah untuk koneksi database saat form aktif
CMDSIMPAN.Enabled = False
CMDEDIT.Enabled = False
CMDHAPUS.Enabled = False
CMDBERSIH.Enabled = False
CMDKELUAR.Enabled = True
Adodc1.Visible = False

Text1.SetFocus
Call kosong
Call koneksi
Adodc1.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\DBKOLEKSI.mdb"
Adodc1.RecordSource = "T_data"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
End Sub

Private Sub Form_Load()
'Text1.Text = ""

Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text4.Enabled = False
End Sub
Private Sub TampilkanData()
Text2 = RSdata!nama
Text3 = RSdata!ALAMAT
Text4 = App.Path & "\foto\NRP_" & Text1.Text & ".jpg"
Set DataGrid1.DataSource = RSdata.DataSource
DataGrid1.Refresh
End Sub
Function CariData()
Call koneksi
RSdata.Open "Select * From T_data where nrp='" & Text1 & "'", conn
End Function
Private Sub kosong()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub simpan()
SavePicture Image1.Picture, App.Path & "\foto\NRP_" & Text1.Text & ".jpg"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Call CariData
    If Not RSdata.EOF Then
        TampilkanData
        MsgBox "Data Ditemukan"
        CMDEDIT.Enabled = True
        CMDHAPUS.Enabled = True
    Else
        Text2.SetFocus
        Text2.Text = ""
        Text3.Text = ""
        Text4.Text = ""
        CMDSIMPAN.Enabled = True
    End If
    
End If
End Sub
Private Sub Text4_Change()
Image1.Picture = LoadPicture(Text4)
End Sub

Interface:












******SEMOGA MEMBANTU******

Komentar

Posting Komentar

Postingan Populer