Module :
Option Explicit
Public conn As New ADODB.Connection
Public sqltxt As String
Sub koneksi()
If conn.State = 1 Then conn.Close
conn.ConnectionString = “Provider=MSDASQL.1;Persist Security Info=False;Data Source=HOST”
conn.CursorLocation = adUseClient
conn.Open
End Sub
Program Utama :
Dim rsmahasiswa As New ADODB.Recordset
Private Sub cmdbatal_Click()
Me.txtnomor.Text = “”
Me.txtnama.Text = “”
Me.txtalamat.Text = “”
Me.txttanggal.Text = “”
Me.txtjenis.Text = “”
Me.txtnomor.SetFocus
Me.cmdbatal.Enabled = False
Me.cmdsimpan.Enabled = False
Me.txtnomor.Enabled = False
Me.txtnama.Enabled = False
Me.txtalamat.Enabled = False
Me.txttanggal.Enabled = False
Me.txtjenis.Enabled = False
End Sub
Private Sub cmdlihat_Click()
Form2.Show vbModal
End Sub
Private Sub cmdsimpan_Click()
‘Periksa isian
If Me.txtnomor.Text = “” Then
MsgBox ” Nomor induk mahasiswa harap diisi”
Me.txtnomor.SetFocus
Exit Sub
End If
If Me.txtnomor.Text = “” Then
MsgBox ” Nomor induk mahasiswa harap diisi”
Me.txtnomor.SetFocus
Exit Sub
End If
If Me.txtnama.Text = “” Then
MsgBox ” Nama mahasiswa harap diisi”
Me.txtnama.SetFocus
Exit Sub
End If
If Me.txtalamat.Text = “” Then
MsgBox ” Alamat mahasiswa harap diisi”
Me.txtalamat.SetFocus
Exit Sub
End If
If Not IsDate(Me.txttanggal.Text) Then
MsgBox ” Tanggal Lahir harap diisi dengan benar”
Me.txttanggal.SetFocus
Exit Sub
End If
If Me.txtjenis.Text <> “L” And Me.txtjenis <> “P” Then
MsgBox ” Jenis Kelamin Harus diisi dengan L atau P”
Me.txtjenis.SetFocus
Exit Sub
End If
‘Periksa apakah nim sudah terpakai
sqltxt = “select * from mahasiswa where nim=’” & Me.txtnomor.Text & “‘”
Set rsmahasiswa = conn.Execute(sqltxt, , adCmdText)
If rsmahasiswa.EOF = False Then
MsgBox “Nomor Induk Mahasiswa sudah terpakai”
Me.txtnomor.SetFocus
Exit Sub
End If
‘Simpan data ke tabel mahasiswa
sqltxt = “insert into Mahasiswa (nim,nama,alamat,tgllahir,jnskelamin) values( ‘” & _
Me.txtnomor.Text & “‘,’” & _
Me.txtnama.Text & “‘, ‘” & _
Me.txtalamat.Text & “‘,’” & _
Format(Me.txttanggal.Text, “yyyy/MM/dd”) & “‘,’” & _
Me.txtjenis.Text & “‘)”
conn.Execute sqltxt, , adCmdText
cmdtambah_Click
End Sub
Private Sub cmdtambah_Click()
Me.txtnomor.Enabled = True
Me.txtnama.Enabled = True
Me.txtalamat.Enabled = True
Me.txttanggal.Enabled = True
Me.txtjenis.Enabled = True
Me.cmdsimpan.Enabled = True
Me.cmdbatal.Enabled = True
Me.txtnomor.Text = “”
Me.txtnama.Text = “”
Me.txtalamat.Text = “”
Me.txttanggal.Text = “”
Me.txtjenis.Text = “”
Me.txtnomor.SetFocus
End Sub
Private Sub cmdtutup_Click()
Unload Me
End Sub
Private Sub Form_Load()
Call koneksi
Me.cmdsimpan.Enabled = False
Me.cmdbatal.Enabled = False
Me.txtnomor.Enabled = False
Me.txtnama.Enabled = False
Me.txtalamat.Enabled = False
Me.txttanggal.Enabled = False
Me.txtjenis.Enabled = False
End Sub
Tidak ada komentar:
Posting Komentar