Rabu, 02 November 2016

Vb6 Connection to Access


Private Sub cmdbersih_Click()
    txtnik.Text = ""
    txtnama.Text = ""
    txtdivisi.Text = ""
    txtjabatan.Text = ""
    txtkerja.Text = ""
    txtlibur.Text = ""
    txtgaji.Text = ""
    txtkdlembur.Text = ""
    txtjslembur.Text = ""
    txtbayar.Text = ""
    txttotallembur.Text = ""
    txttotalgaji.Text = ""
   
    txtnik.SetFocus

End Sub

Private Sub cmdcari_Click()
      Dim Sumber As String
      Dim Rs As New Recordset
      Dim Cm As New Command
      Dim Kunci As String
     
      Kunci = "%" + txtcari + "%"
     
      Sumber = " Select * From Karyawan " & _
            " where Nik Like :X or Nama_Karyawan Like :Y "
           
      Cm.ActiveConnection = MYconn
      Cm.CommandText = Sumber
     
      Cm.Parameters(0).Value = Kunci
      Cm.Parameters(1).Value = Kunci
     
      Set Rs = Cm.Execute
      Set MSHFlexGrid1.DataSource = Rs
     
      If Not Rs.EOF Then
         Rs.MoveFirst
      End If
     
      Dim Z As Integer
     
      Z = 1
      While Not Rs.EOF
        MSHFlexGrid1.TextMatrix(Z, 1) = Rs!Nik
        MSHFlexGrid1.TextMatrix(Z, 2) = Rs!Nama_Karyawan
        MSHFlexGrid1.TextMatrix(Z, 3) = Rs!Divisi
        MSHFlexGrid1.TextMatrix(Z, 4) = Rs!Jabatan
        MSHFlexGrid1.TextMatrix(Z, 5) = Rs!Hari_Kerja
        MSHFlexGrid1.TextMatrix(Z, 6) = Rs!Hari_Libur
        MSHFlexGrid1.TextMatrix(Z, 7) = Rs!Gaji
       
        Rs.MoveNext
       
        Z = Z + 1
        MSHFlexGrid1.AddItem ("")
    Wend

End Sub

Private Sub cmdexit_Click()
    End
End Sub

Private Sub cmdgaji_Click()
    txttotalgaji.Text = Val(txttotallembur.Text) + Val(txtgaji.Text)
End Sub

Private Sub cmdhapus_Click()
    Dim Cm As New Command
    Dim Sumber As String
    Dim Kunci As String
   
    'Kunci = txtnik.text
    Kunci = InputBox(" Masukan Nik yang akan dihapus ")
   
    If Kunci = "" Then
        MsgBox "Nik belum dimasukan, Masukan Nik : "
        Exit Sub
    End If
   
    On Error GoTo salah
   
    Sumber = " Delete From Karyawan Where Nik =:NoNik "
   
    Cm.ActiveConnection = MYconn
    Cm.CommandText = Sumber
   
    Cm.Parameters(0).Value = Kunci
   
    Cm.Execute
   
benar:
    MsgBox "Data sudah dihapus"
    Exit Sub
   
salah:
    MsgBox Err.Description
End Sub

Private Sub cmdrubah_Click()
    Dim Cm As New Command
    Dim Sumber As String
   
    On Error GoTo salah
   
    Sumber = " Update Karyawan Set Nama_Karyawan =:Nama_Karyawan, Divisi =:Divisi, " & _
             " Jabatan =:Jabatan, Hari_Kerja =:Hari_Kerja, Hari_Libur =:Hari_Libur, Gaji =:Gaji " & _
             " Where NIK =:NIK "
           
    Cm.ActiveConnection = MYconn
    Cm.CommandText = Sumber
   
    Cm.Parameters(0).Value = txtnama
    Cm.Parameters(1).Value = txtdivisi
    Cm.Parameters(2).Value = txtjabatan
    Cm.Parameters(3).Value = txtkerja
    Cm.Parameters(4).Value = txtlibur
    Cm.Parameters(5).Value = txtgaji
    Cm.Parameters(6).Value = txtnik
   
    Cm.Execute
   
betul:
    MsgBox "Data telah dirubah"
    Exit Sub
   
salah:
    MsgBox "Masih ada yang salah"
End Sub

Private Sub cmdsimpan_Click()
    Dim Sumber As String
    Dim Cm As New Command
   
    On Error GoTo salah
   
    If txtnik.Text = "" Then
        MsgBox "Masukan Nik dahulu"
    End If
   
    Sumber = " Insert into Karyawan Values ( :Nik, :Nama_Karyawan, :Divisi, :Jabatan, :Hari_Kerja, :Hari_Libur, :Gaji ) "
   
    Cm.ActiveConnection = MYconn
    Cm.CommandText = Sumber
   
    Cm.Parameters(0).Value = txtnik
    Cm.Parameters(1).Value = txtnama
    Cm.Parameters(2).Value = txtdivisi
    Cm.Parameters(3).Value = txtjabatan
    Cm.Parameters(4).Value = txtkerja
    Cm.Parameters(5).Value = txtlibur
    Cm.Parameters(6).Value = txtgaji
   
    Cm.Execute
   
betul:
    MsgBox "Data sudah di simpan"
    Exit Sub
   
salah:
    MsgBox Err.Description
   
    End Sub

Private Sub cmdtampil_Click()
    Dim Rs As New Recordset
    Dim Cm As New Command
    Dim Sumber As String
    Dim Kunci As String
   
    'Masukan kunci dalam Input Box
    Kunci = txtnik.Text
   
    If Kunci = "" Then
       Exit Sub
    End If
   
    'Isi sumber dari Tabel PMBPPM dgn Kunci No Formulir
    Sumber = " Select * From Karyawan Where NIK =:Kunci  "
   
    'Aktifkan Connection String
    Cm.ActiveConnection = MYconn
    Cm.CommandText = Sumber
   
    'Isi No Formulir dengan Kunci
    Cm.Parameters(0).Value = Kunci
   
    'Rs Dilaksanakan
    Set Rs = Cm.Execute
   
    If Rs.EOF Then
       txtnik.SetFocus
       Exit Sub
    Else
        txtnik.Text = Rs!Nik
        txtnama.Text = Rs!Nama_Karyawan
        txtdivisi.Text = Rs!Divisi
        txtjabatan.Text = Rs!Jabatan
        txtkerja.Text = Rs!Hari_Kerja
        txtlibur.Text = Rs!Hari_Libur
        txtgaji.Text = Rs!Gaji
              MsgBox " Tampil Data Ok "
    End If

End Sub

Private Sub Form_Load()
    MYconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Program\Ms Access\Data Karyawan.mdb;Persist Security Info=False"
End Sub

Private Sub Option1_Click()
    If Option1 = True Then
        txttotallembur.Text = 1 * txtbayar.Text
    End If
   
End Sub

Private Sub Option2_Click()
    If Option2 = True Then
        txttotallembur.Text = 2 * txtbayar.Text
    End If
End Sub

Private Sub Option3_Click()
    If Option3 = True Then
        txttotallembur.Text = 3 * txtbayar.Text
    End If
End Sub


Private Sub txtkdlembur_Change()
    If txtkdlembur.Text = "ML" Then
       txtjslembur.Text = "Malam Lembur"
       txtbayar.Text = 70000
       Else
         If txtkdlembur.Text = "PL" Then
            txtjslembur.Text = "Pagi Lembur"
            txtbayar.Text = 60000
         Else
           If txtkdlembur.Text = "LS" Then
              txtjslembur.Text = "Long Shift"
              txtbayar.Text = 100000
           End If
        End If
    End If
   
End Sub

Tidak ada komentar:

Posting Komentar