Koneksi visual Basic dengan Microsoft Office Access 2007

Posted by Hanafi Sukawa G. On Thursday, May 6, 2010 1 comments
Kali ini saya mencoba membuat koneksi visual basic dengan Microsoft Office Access 2007.

tutorianya lihat di bawah :


Tampilan Input data



Tampilan Output Data




Public con As New ADODB.Connection
Public rec As New ADODB.Recordset


Public Sub koneksi()

con.Open "provider = microsoft.ace.oledb.12.0; data source = " & App.Path & "\Database1.accdb"

End Sub


Private Sub Close_Click()
Unload Me
End Sub

Private Sub cmdexit_Click()
End
End Sub

Private Sub cmdsimpan_Click()

If txtnrp.Text = "" Then
MsgBox "Isi NRP"
txtnrp.SetFocus
ElseIf Len(txtnrp) < text = "" text = ""> 8 Then
MsgBox "Semester tidak lebih dari 8"
cmbsemester.SetFocus
ElseIf cmbk.Text = "" Then
MsgBox "pilih kelas"
cmbk.SetFocus
ElseIf cmbk.Text > 3 Then
MsgBox "kelas yang anda pilih tidak ada"
cmbk.SetFocus
ElseIf cmbj = "" Then
MsgBox "pilih jurusan"
cmbj.SetFocus
ElseIf cmbn.Text = "" Then
MsgBox "pilih kelas keberapa"
cmbn.SetFocus
ElseIf cmbn.Text > 10 Then
MsgBox "Kelas yang anda pilih tidak ada"
cmbn.SetFocus

Else
con.Execute "insert into mahasiswa values('" & txtnrp & "','" & txtnama & "','" & cmbsemester & "','" & cmbk + " " + cmbj + " " + "-" + " " + cmbn & "')"
MsgBox "Data tersimpan", vbInformation, simpan
tampil
txtnrp.Text = ""
txtnama.Text = ""
cmbsemester.Text = ""
cmbk.Text = ""
cmbj.Text = ""
cmbn.Text = ""
txtnrp.Enabled = False
txtnama.Enabled = False
cmbsemester.Enabled = False
cmdsimpan.Enabled = False
cmbk.Enabled = False
cmbj.Enabled = False
cmbn.Enabled = False

End If



End Sub



Private Sub cmdtambah_Click()
txtnrp.Text = ""
txtnama.Text = ""
cmbsemester.Text = ""
cmbk.Text = ""
cmbj.Text = ""
cmbn.Text = ""

txtnrp.Enabled = True
txtnama.Enabled = True
cmbsemester.Enabled = True
cmdsimpan.Enabled = True
cmbk.Enabled = True
cmbj.Enabled = True
cmbn.Enabled = True

End Sub

Sub tampil()
rec.Open "Select * from mahasiswa ", con, adOpenKeyset, adLockOptimistic
Set grid.DataSource = Nothing
Set grid.DataSource = rec
rec.Close
End Sub


Private Sub Form_Load()


koneksi
tampil

End Sub




Untuk kompile filenya download di sini

1 comments to Koneksi visual Basic dengan Microsoft Office Access 2007

  1. says:

    Anonymous cara koneksi vb 2010 ke acces 2007 dong. butuh pencerahan banget nih.

Post a Comment

email : hanafi@newscomputers.co.nr