Assalamu'alaikum wr.wb
Ini adalah cara untuk mengkoneksikan Ms.Access ke Visual Basic dan yang saya gunakan adalah Visual Basic 6.0.Pertama-tama yang harus dibuat yaitu databasenya dulu menggunakanMs.Access seperti contoh dibawah.
Nah Guys... setelah database sudah dibuat
selanjutnya buka Visual Basic 6.0.Untuk pewarnaan dan layout bisa menurut kreatifitas masing-masing.Oh iya
klik kanan pada jendela toolbox yang kosong lalu pilih add komponen.Kemudian
akan tampil seperti dibawah dan jangan
lupa Checklist komponen yang diperlukan lalu klik OK.
Jika
sudah tampil komponen yang akan digunakan silahkan dibuat form1 seperti dibawah
ini sesuai kreasi yaaa.....
Jangan lupa pada form1 BorderStylenya :
0-none dan StarUpPositionnya : 1-CenterOwner.
Jika
sudah selesai mendesaign form1 silahkan ketik skript untuk form1 seperti
dibawah ini.
Private Sub command1_click()
If conn.State = 1 Then conn.Close
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=DataBase.mdb;Persist Security Info=False"
If
RS.State = 1 Then RS.Close
RS.Open "select *from admin where User_name= '" &
Text1.Text & "' and Password= '" & Text2.Text &
"'", conn, adOpenDynamic
If Not RS.EOF Then
MsgBox "Selamat Datang Di Praktikum Provis Kelas D"
Form2.Show
Form1.Hide
Else
MsgBox "Data Salah", vbCritical, "LOGIN"
End
If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Text1_GotFocus()
If
Text1.Text = "Username" Then
Text1.Text = ""
End
If
End Sub
Private Sub text1_LostFocus()
If
Text1.Text = "" Then
Text1.Text = "Username"
End
If
End Sub
Private Sub text2_GotFocus()
If
Text2.Text = "Password" Then
Text2.Text = ""
End
If
End Sub
Private Sub text2_LostFocus()
If
Text2.Text = "" Then
Text2.Text = "Password"
End
If
End Sub
Private Sub text2_change()
Text2.PasswordChar = "*"
End Sub
Nah ini adalah tampilan untuk form2 silahkan
dibuat sekreatif mungkin tanpa mengabaikan icon-icon yang seharusnya digunakan.
Silahkan buat skript untuk form2 seperti
dibawah ini.
Private Sub command1_click()
Form1.Show
Form2.Hide
End Sub
Private Sub Command2_Click()
Form3.Show
Form2.Hide
End Sub
Private Sub Form_Load()
Call koneksi
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=DataBase.mdb;Persist Security Info=False"
Adodc1.RecordSource = "admin"
Adodc1.RecordSource = "select *from admin"
Adodc1.Refresh
Set
DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
End Sub
Ini tampilan untuk form3,silahkan dibuat.
Silahkan buat skript untuk form3 seperti
dibawah ini.
Private Sub command1_click()
Dim
SQLSimpan As String
If (Text1.Text = "ID Admin" Or Text2.Text =
"Nama_Admin" Or Text3 = "User_name" Or Text4 =
"Password") Then
MsgBox "Isi Data Dengan Lengkap"
Text1.SetFocus
Else
If IsNumeric(Text2.Text) Then
MsgBox "Nama Harus
Huruf"
Text2.Text = ""
Text2.SetFocus
Exit Sub
End If
Call koneksi
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=DataBase.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from
admin"
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("id_admin")
= Text1.Text
Adodc1.Recordset.Fields("nama_admin")
= Text2.Text
Adodc1.Recordset.Fields("user_name")
= Text3.Text
Adodc1.Recordset.Fields("password")
= Text4.Text
Adodc1.Recordset.Update
End If
Form2.Show
Form3.Hide
Form1.Hide
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub label1_click()
Form1.Show
Form3.Hide
End Sub
Private Sub Text1_GotFocus()
If
Text1.Text = "ID ADMIN" Then
Text1.Text = ""
End
If
End Sub
Private Sub text1_LostFocus()
If
Text1.Text = "" Then
Text1.Text = "ID ADMIN"
End
If
End Sub
Private Sub text2_GotFocus()
If
Text2.Text = "NAMA ADMIN" Then
Text2.Text = ""
End
If
End Sub
Private Sub text2_LostFocus()
If
Text2.Text = "" Then
Text2.Text = "NAMA ADMIN"
End
If
End Sub
Private Sub Text3_GodFocus()
If
Text3.Text = "USERNAME" Then
Text3.Text = ""
End
If
End Sub
Private Sub Text3_LostFocus()
If
Text3.Text = "" Then
Text3.Text = "USERNAME"
End
If
End Sub
Private Sub text4_GotFocus()
If
Text4.Text = "PASSWORD" Then
Text4.Text = ""
End
If
End Sub
Private Sub text4_LostFocus()
If
Text4.Text = "" Then
Text4.Text = "PASSWORD"
End
If
End Sub
Ini adalah skript untuk module.
Public conn As New ADODB.Connection
Public RS As New ADODB.Recordset
Public RSdata As New ADODB.Recordset
Sub koneksi()
Set
konek = New ADODB.Connection
Set
RSdata = New ADODB.Recordset
konek.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=DataBase.mdb;Persist Security Info=False"
End Sub
Kalau sudah selesai tinggal di RUN aja, kalau
ga’ jalan coba periksa-periksa lagi siapa tahu Cuma salah nama doank !!!
hehe...
Yang sudah bisa silahkan mencoba yang lain lagi biar tambah mahir.
Yang sudah bisa silahkan mencoba yang lain lagi biar tambah mahir.
Untuk lebih jelasnya silahkan download programnya disini http://www.4shared.com/rar/l0Q51lp_/latihan_provis.html
Wassalam...
terimakasih sudah membaca !!! :)
Tidak ada komentar:
Posting Komentar