Oleh :
Nama
Fauziah
NOBP
11101156110017
Kelas
TIK-1
1. Pastikanlah terlebih dahulu VB 6.0 dan database mySql nya telah terinstall dengan baik.
2. Click start >> program >> Microsoft Visual Studio >> Microsoft Visual Basic 6.0
3. Pilih
4. Buatlah form seperti dibawah ini
Created By Fauziah
Created By Fauziah
Gambar MDI form (cara membuat mdi form adalah dengan klik kanan pada form lalu
klik add >> MDI form).
5. Lalu tambahkan juga form module dengan klik kanan >> add >> module
6. Langkah selanjutnya buatlah database baru.
7. Buat 4 buah tabel baru dan isi fieldnya sesuaikan dengan kebutuhan
Created By Fauziah
Gambar tabel data mata pelajaran dengan kode_mapel sebagai primary key.
Created By Fauziah
ADODC Properties >> use connection string >> use data source name >> pilih data base
yg telah dibuat (dalam kasus ini menggunakan database db_barang) >> test connection
terlebih dahulu >> ok.
13. Masih pada properties pada Adodc pilih >> setelah dibuat seperti gambar dibawah tekan
ok
14. Lalu pada Datagrid1 ubah lah datasourcenya menjadi Adodc1 pada properties
15. Dan begitulah langkah selanjutnya yang dilakukan pada form-form yang lain, dan hanya
memerlukan perubahan nama table penghubung dengan database MySQL.
16. Dan langkah selanjutnya sesuiakan lah script berikut ini
Form Input data siswa
Private Sub cmd_cancel_Click()
kosong
Call tabel
End Sub
Private Sub cmd_clear_Click()
kosong
Call tabel
End Sub
Private Sub cmd_edit_Click()
conn.Execute "update data_siswa set nama='" & Text2.Text & "',jurusan='" &
Combo1.Text & "',kelas='" & Text3.Text & "' where nis='" & Text1.Text & "'"
MsgBox "Data berhasil di update..", vbOKOnly + vbInformation
kosong
Call tabel
DataGrid1.Refresh
Adodc1.Refresh
Created By Fauziah
End Sub
Private Sub cmd_hapus_Click()
If Text1.Text = "" Then
MsgBox "Error! No Record Has Been Selected", vbCritical, "No Record
Selected!"
Else
With rsdatasiswa
'Confirm the Delete procedure with the user
If MsgBox("Are You Sure You Wish To Delete Room ID " & Text1.Text & "'s
Record?", vbYesNo + vbQuestion, "Delete Record?") = vbYes Then
.Delete 'Delete the record from the database
'Display Success Message
MsgBox "The Record Has Been Deleted Successfully!", vbInformation,
"Successful Delete Procedure!"
Form_Load 'Calling the Form_Load Procedure
clearAllFields 'Calling a Private Function To Clear All Fields
Else
'Display 'Delete Procedure Cancelled' Message
MsgBox "The Delete Procedure Was Cancelled!", vbExclamation, "Delete
Procedure Cancelled!"
Form_Load 'Calling the Form_Load Procedure
clearAllFields 'Calling a Private Function To Clear All Fields
End If
.Requery
End With
End If
End Sub
Public Function clearAllFields() 'This function will clear all fields on the interface
Created By Fauziah
'
'
'
'
'
'Entering the values in the particular record into the fields on the interface
Text1.Text = .Fields(0).Value
Text2.Text = .Fields(1).Value
Combo1.Text = .Fields(2).Value
Text3.Text = .Fields(3).Value
' texttelpsupplier.Text = .Fields(3).Value
txtWardID.Text = .Fields(4).Value
txtWardNumber.Text = .Fields(5).Value
txtRoomCost.Text = .Fields(6).Value
txtAdditionalNotes.Text = .Fields(7).Value
End With
enableAllFields
End Sub
Private Sub Form_Load()
Combo1.AddItem ("IPA")
Created By Fauziah
Combo1.AddItem ("IPS")
Combo1.AddItem ("BAHASA")
If conn.State = adStateClosed Then
main
End If
Call tabel
Call datasiswa_Maintenance
Set DataGrid1.DataSource = rsdatasiswa
DataGrid1.Enabled = True
End Sub
Sub kosong()
Text1.Text = ""
Text2.Text = ""
Combo1.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub
Private Sub tabel()
Set rec = New ADODB.Recordset
rec.CursorLocation = adUseClient
rec.Open "select * from data_siswa", conn, adOpenForwardOnly, adLockReadOnly
Set DataGrid1.DataSource = rec
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If rec.State Then rec.Close
rec.Open "select * from data_siswa where nis='" & Text1.Text & "'", conn,
adOpenForwardOnly, adLockReadOnly
If Not rec.EOF Then
Text2.Text = rec("nama")
Combo1.Text = rec("jurusan")
Text3.Text = rec("kelas")
Call tabel
MsgBox "data sudah ada", vbInformation + vbOKOnly
Else
Text2.Text = ""
Combo1.Text = ""
Text3.Text = ""
Text2.SetFocus
Call tabel
End If
rec.Close
End If
End Sub
Created By Fauziah
Created By Fauziah
End With
End If
End Sub
Public Function clearAllFields() 'This function will clear all fields on the interface
On Error Resume Next
For Each eachField In Me.Controls 'Running a Loop through all the Controls
'The following If Condition will clear all TextBoxes
If TypeOf eachField Is TextBox Then
eachField.Text = ""
End If
Next
End Function
Private Sub Command4_Click()
kosong
Call tabel
End Sub
Private Sub Command5_Click()
Unload Me
End Sub
Private Sub DataGrid1_Click()
With rsdatamapel
'Entering the values in the particular record into the fields on the interface
Text1.Text = .Fields(0).Value
Text2.Text = .Fields(1).Value
Text3.Text = .Fields(2).Value
Created By Fauziah
'
'
'
'
Text4.Text = .Fields(3).Value
' texttelpsupplier.Text = .Fields(3).Value
txtWardID.Text = .Fields(4).Value
txtWardNumber.Text = .Fields(5).Value
txtRoomCost.Text = .Fields(6).Value
txtAdditionalNotes.Text = .Fields(7).Value
End With
' enableAllFields
End Sub
Private Sub Form_Load()
If conn.State = adStateClosed Then
main
End If
Call tabel
Call datamapel_Maintenance
Set DataGrid1.DataSource = rsdatamapel
DataGrid1.Enabled = True
End Sub
Sub kosong()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text1.SetFocus
End Sub
Private Sub tabel()
Set rec = New ADODB.Recordset
rec.CursorLocation = adUseClient
rec.Open "select * from data_mapel", conn, adOpenForwardOnly, adLockReadOnly
Set DataGrid1.DataSource = rec
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If rec.State Then rec.Close
rec.Open "select * from data_mapel where kode_mapel='" & Text2.Text & "'", conn,
adOpenForwardOnly, adLockReadOnly
If Not rec.EOF Then
Text1.Text = rec("kode_guru")
Text3.Text = rec("nama_mapel")
Text4.Text = rec("sks")
Call tabel
MsgBox "data sudah ada", vbInformation + vbOKOnly
Else
Created By Fauziah
Text1.Text = ""
Text3.Text = ""
Text4.Text = ""
Text1.SetFocus
Call tabel
End If
rec.Close
End If
End Sub
Form input data guru
Private Sub Command1_Click()
conn.Execute ("insert into data_guru values('" & txt_kdguru.Text & "','" &
txt_nmguru.Text & "')")
MsgBox "Data berhasil di simpan..", vbOKOnly + vbInformation
kosong
Call tabel
DataGrid1.Refresh
Adodc1.Refresh
End Sub
Private Sub Command2_Click()
conn.Execute "update data_guru set nama_guru='" & txt_nmguru & "' where
kode_guru='" & txt_kdguru & "'"
MsgBox "Data berhasil di update..", vbOKOnly + vbInformation
kosong
Call tabel
DataGrid1.Refresh
Adodc1.Refresh
End Sub
Private Sub Command3_Click()
'conn.Execute "delete from data_guru where kode_guru='" & txt_kdguru & "'"
'MsgBox "Data berhasil di hapus..", vbOKOnly + vbInformation
'kosong
'Call tabel
'If txt_kdguru = "" Then
'MsgBox ("data tidak lengkap,gagal menghapus data...!")
'Exit Sub
'End If
'Dim x As String
'x = MsgBox("Ingin Hapus data ini? [Y/N]", vbYesNo + vbQuestion)
'If x = vbYes Then
' conn.Execute ("delete from data_guru where kode_guru='" & Trim(txt_kdguru) &
"'")
Created By Fauziah
End With
End If
End Sub
Public Function clearAllFields() 'This function will clear all fields on the interface
Created By Fauziah
End Sub
Private Sub Form_Load()
If conn.State = adStateClosed Then
main
End If
Created By Fauziah
Call tabel
Call dataguru_Maintenance
Set DataGrid1.DataSource = rsdataguru
DataGrid1.Enabled = True
End Sub
Private Sub txt_kdguru_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If rec.State Then rec.Close
rec.Open "select * from data_guru where kode_guru='" & txt_kdguru & "'", conn,
adOpenForwardOnly, adLockReadOnly
If Not rec.EOF Then
txt_nmguru = rec("nama_guru")
Call tabel
MsgBox "data sudah ada", vbInformation + vbOKOnly
Else
txt_nmguru = ""
txt_nmguru.SetFocus
Call tabel
End If
rec.Close
End If
End Sub
Private Sub tabel()
Set rec = New ADODB.Recordset
rec.CursorLocation = adUseClient
rec.Open "select * from data_guru", conn, adOpenForwardOnly, adLockReadOnly
Set DataGrid1.DataSource = rec
End Sub
Script untuk MDI Form
Private Sub dataguru_Click()
entry_dataguru.Show
End Sub
Private Sub datamapel_Click()
entry_datamapel.Show
End Sub
Private Sub datasiswa_Click()
entry_datasiswa.Show
End Sub
Private Sub edit_Click()
Created By Fauziah
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Private Sub nilaisiswa_Click()
entry_nilaisiswa.Show
End Sub
Note: untuk memfullscreen kan ubah windowstate menjadi maximized
Script pada module1
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public rsnilai As ADODB.Recordset
Public rsdatasiswa As ADODB.Recordset
Public rsdatamapel As ADODB.Recordset
Public rsdataguru As ADODB.Recordset
Sub main()
'The Purpose of this function is to open a connection to link the database
Set conn = New ADODB.Connection
'Provider=MSDASQL.1;Password=root;Persist Security Info=True;User
ID=root;Data Source=konekpersediaan_aj
conn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User
ID=root;Data Source=db_barang"
End Sub
Public Sub nilai_Maintenance()
'The Purpose of this function is to manage the recordset "Rooms_Maintenance"
Created By Fauziah
Created By Fauziah
Created By Fauziah
Created By Fauziah
Created By Fauziah
Created By Fauziah
Created By Fauziah
Script di module
Global db As Connection
Global rs As Recordset
Sub main()
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "fauziah"
Form1.Show
End Sub
Created By Fauziah