Minggu, 19 Februari 2017

'Aplikasi Pemilu Sederhana  VB 6.0 & Acses.mdb
'KODE====================================================
'Komentar email ke: axkhan23@gmail.com
'ALEX W K  :)
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim db1 As ADODB.Connection
Dim rs1 As ADODB.Recordset

Private Sub Check1_Click()
If Check1.Value = 1 Then
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Else
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
End If
End Sub

Private Sub Command1_Click()
On Error Resume Next
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"

Command1.Enabled = False
Text3 = 2
'=======================
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
db.Open "", ""
a = "select * from Table1"
rs.Open a, db, adOpenDynamic, adLockOptimistic, adCmdText
rs.Requery

Set db1 = New ADODB.Connection
Set rs1 = New ADODB.Recordset
db1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
db1.Open "", ""
b = "select * from Table1"
rs1.Open b, db1, adOpenDynamic, adLockOptimistic, adCmdText
rs1.Requery

'==========================

Text2 = "Jokowi-Jusuf"
Text1 = 1
a = MsgBox("Apakah anda yakin JOKOWI JUSUF... ", vbYesNo, "Pesan")
If a = vbYes Then
Set rs1 = db1.Execute("select * from table1 where nama_kandidat='" & Text2.Text & "'")
If rs1.EOF Then
Set rs = db.Execute("update  table1 " & _
 "set jumlah_suara ='" & Text1.Text & "'" & _
 " where nama_kandidat='" & Text2.Text & "'")
 'Pouse 1
Timer1.Enabled = True

 Exit Sub
Else
num = rs1!jumlah_suara
Text1 = num + 1
End If

Set rs = db.Execute("update  table1 " & _
 "set jumlah_suara ='" & Text1.Text & "'" & _
 " where nama_kandidat='" & Text2.Text & "'")
MsgBox "Data telah terupdate....!", vbInformation, "Pesan"

Adodc1.Refresh

DataGrid1.Refresh

bersih

'Pouse 1
Timer1.Enabled = True
Else
Timer1.Enabled = True

End If
End Sub

Private Sub Command2_Click()
On Error Resume Next
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
Command2.Enabled = False
Text3 = 1
'=======================
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
db.Open "", ""
a = "select * from Table1"
rs.Open a, db, adOpenDynamic, adLockOptimistic, adCmdText
rs.Requery

Set db1 = New ADODB.Connection
Set rs1 = New ADODB.Recordset
db1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
db1.Open "", ""
b = "select * from Table1"
rs1.Open b, db1, adOpenDynamic, adLockOptimistic, adCmdText
rs1.Requery

'==========================
Text2 = "Prabowo-Hatta"
Text1 = 1
a = MsgBox("Apakah anda yakin PRABOWO HATTA... ", vbYesNo, "Pesan")
If a = vbYes Then
Set rs1 = db1.Execute("select * from table1 where nama_kandidat='" & Text2.Text & "'")
If rs1.EOF Then
Set rs = db.Execute("update  table1 " & _
 "set jumlah_suara ='" & Text1.Text & "'" & _
 " where nama_kandidat='" & Text2.Text & "'")
' Pouse 2
Timer1.Enabled = True

 Exit Sub
Else
num = rs1!jumlah_suara
Text1 = num + 1
End If

Set rs = db.Execute("update  table1 " & _
 "set jumlah_suara ='" & Text1.Text & "'" & _
 " where nama_kandidat='" & Text2.Text & "'")
MsgBox "Data telah terupdate....!", vbInformation, "Pesan"

Adodc1.Refresh

DataGrid1.Refresh

bersih
'Pouse 1
Timer1.Enabled = True

Else
Timer1.Enabled = True

End If
End Sub



Private Sub Command3_Click()
On Error Resume Next

ALX = MsgBox("ANDA INGIN MERESET JUMLAH SUARA KE O....! PILIH YES UNTUK MELANJUTKAN DAN NO UNTUK BATAL....!", vbYesNo, "PERINGATAN")
If ALX = vbYes Then
Text2 = "Prabowo-Hatta"
Text1 = 0
Set rs = db.Execute("update  table1 " & _
 "set jumlah_suara ='" & Text1.Text & "'" & _
 " where nama_kandidat='" & Text2.Text & "'")

Pouse 1
Text2 = "Jokowi-Jusuf"
Text1 = 0
Set rs = db.Execute("update  table1 " & _
 "set jumlah_suara ='" & Text1.Text & "'" & _
 " where nama_kandidat='" & Text2.Text & "'")
MsgBox "Data telah terupdate....!", vbInformation, "Pesan"
bersih
Text4 = 0
Text5 = 0
 Adodc1.Refresh
 DataGrid1.Refresh

 Else
 End If
End Sub

Private Sub Command4_Click()
On Error Resume Next

ALX = MsgBox("ANDA MELAKUKAN PROSES PENAMBAHAN...!, INGIN DILANJUTKAN...?", vbYesNo, "PERINGATAN")
If ALX = vbYes Then
Text2 = "Prabowo-Hatta"
Text1 = 0

Set rs = db.Execute("select * from table1 where nama_kandidat='" & Text2.Text & "'")
If rs.EOF Then
Else
Text1 = rs!jumlah_suara
End If

Text1 = Val(Text1.Text) + Val(Text6.Text)
Set rs = db.Execute("update  table1 " & _
 "set jumlah_suara ='" & Text1.Text & "'" & _
 " where nama_kandidat='" & Text2.Text & "'")
MsgBox "Data telah terupdate....!", vbInformation, "Pesan"
bersih
 Adodc1.Refresh
 DataGrid1.Refresh
 Else
 End If
End Sub

Private Sub Command5_Click()
On Error Resume Next
ALX = MsgBox("ANDA MELAKUKAN PROSES PENAMBAHAN...!, INGIN DILANJUTKAN...?", vbYesNo, "PERINGATAN")
If ALX = vbYes Then
Text2 = "Jokowi-Jusuf"
Text1 = 0

Set rs = db.Execute("select * from table1 where nama_kandidat='" & Text2.Text & "'")
If rs.EOF Then
Else
Text1 = rs!jumlah_suara
End If

Text1 = Val(Text1.Text) + Val(Text7.Text)
Set rs = db.Execute("update  table1 " & _
 "set jumlah_suara ='" & Text1.Text & "'" & _
 " where nama_kandidat='" & Text2.Text & "'")
MsgBox "Data telah terupdate....!", vbInformation, "Pesan"
bersih
 Adodc1.Refresh
 DataGrid1.Refresh
 Else
 End If
End Sub

Private Sub Command6_Click()
'On Error Resume Next
Text2 = "Jokowi-Jusuf"

Set dbrs = New ADODB.Connection
Set rsrs = New ADODB.Recordset

dbrs.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
dbrs.Open "", ""
ars = "select * from Table1"
rsrs.Open ars, dbrs, adOpenDynamic, adLockOptimistic, adCmdText
rsrs.Requery

Set rsrs = dbrs.Execute("select * from table1 where nama_kandidat='" & Text2.Text & "'")
If rsrs.EOF Then
 If Text2 = "Jokowi-Jusuf" Then
 Text5 = rsrs!jumlah_suara
    Else
 Text4 = rsrs!jumlah_suara
 End If
Else
 If Text2 = "Jokowi-Jusuf" Then
 Text5 = rsrs!jumlah_suara
    Else
 Text4 = rsrs!jumlah_suara
 End If
End If

Text2.Text = ""
End Sub

Private Sub Command7_Click()
Text2 = "Prabowo-Hatta"

Set dbrst1 = New ADODB.Connection
Set rsrst1 = New ADODB.Recordset

dbrst1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
dbrst1.Open "", ""
arrst1 = "select * from Table1"
rsrst1.Open arrst1, dbrst1, adOpenDynamic, adLockOptimistic, adCmdText
rsrst1.Requery

Set rsrst1 = dbrst1.Execute("select * from table1 where nama_kandidat='" & Text2.Text & "'")
If rsrst1.EOF Then
 If Text2 = "Jokowi-Jusuf" Then
 Text5 = rsrst1!jumlah_suara
    Else
 Text4 = rsrst1!jumlah_suara
 End If
Else
 If Text2 = "Jokowi-Jusuf" Then
 Text5 = rsrst1!jumlah_suara
    Else
 Text4 = rsrst1!jumlah_suara
 End If
End If
End Sub

Private Sub Form_Load()
On Error GoTo Alex_W_K
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
db.Open "", ""
a = "select * from Table1"
rs.Open a, db, adOpenDynamic, adLockOptimistic, adCmdText
rs.Requery

Set db1 = New ADODB.Connection
Set rs1 = New ADODB.Recordset
db1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
db1.Open "", ""
b = "select * from Table1"
rs1.Open b, db1, adOpenDynamic, adLockOptimistic, adCmdText
rs1.Requery
Text1 = ""
Text2 = ""
Text3 = ""
Check1.Value = 1

Exit Sub
Alex_W_K:
MsgBox "Koneksi database.....!/ Periksa apakah file database sudah terkopi atw belum....", vbInformation, "Pesan"

End Sub

Sub bersih()
On Error Resume Next

Set rs = db.Execute("select * from table1 where nama_kandidat='" & Text2.Text & "'")
If rs.EOF Then
 If Text2 = "Jokowi-Jusuf" Then
 Text5 = rs!jumlah_suara
    Else
 Text4 = rs!jumlah_suara
 End If
Else
 If Text2 = "Jokowi-Jusuf" Then
 Text5 = rs!jumlah_suara
    Else
 Text4 = rs!jumlah_suara
 End If
End If

Text1 = ""
Text2 = ""
Text3 = ""
Text1.SetFocus
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpemilu.mdb" & ";Persist Security Info=False"
DataGrid1.Refresh

End Sub
Sub Pouse(angka)
Dim pos As Integer
Tim = Timer
Do
If Timer - Tim > angka Then Exit Sub
pos = DoEvents()
Loop
End Sub

Private Sub Text3_Change()
Label4.Caption = Text3.Text
End Sub

Private Sub Text4_Change()
chrt.Row = 1
chrt.Data = Text4.Text
End Sub

Private Sub Text5_Change()
chrt.Row = 2
chrt.Data = Text5.Text
End Sub

Private Sub Timer1_Timer()
Adodc1.Refresh
DataGrid1.Refresh
Pouse 1
Command1.Enabled = True
Command2.Enabled = True
End Sub


Tampilan Aplikasi Desktop :