Contoh Coding program VB
Public cn As
New ADODB.Connection
Public rs As
New ADODB.Recordset
Public sql
As String
Dim no_rumah
As String
Dim
type_rumah As String
Dim
model_rumah As String
Dim
luas_tanah As String
Dim
pesan_hapus As String
Dim
pesan_edit As String
Private Sub Form_Load()
cn.Open
"Provider=MSDASQL.1;Persist Security Info=true;Data Source=tugas_uas"
End Sub
Private Sub
simpan1_Click(Index As Integer)
pesan =
MsgBox("YAKIN MAU DISIMPAN...?", vbQuestion + vbYesNo,
"SIMPAN...")
no_rumah =
Text1.Text
luas_tanah =
Text2.Text
model_rumah
= Combo1
If Option1.Value = True Then
type_rumah = "50"
ElseIf
Option2.Value = True Then
type_rumah = "55"
ElseIf
Option3.Value = True Then
type_rumah = "70"
Else
type_rumah = ""
End If
Text1.SetFocus
sql = "insert into tb_rumah
(NO_RMH,TYPE,MODEL,LUAS) Values('" & no_rumah & "','"
& type_rumah & "','" & model_rumah & "','"
& luas_tanah & "')"
cn.Execute sql
Text1.Text = ""
Text2.Text = ""
Combo1 = ""
Option1.Value = False
Option2.Value = False
Option3.Value = False
End Sub
Private Sub
cari1_Click()
sql =
"select * from tb_rumah where NO_RMH = '" & Text1.Text &
"'"
Set rs =
cn.Execute(sql)
If Not
rs.EOF Then
Text2.Text = rs!LUAS
Combo1 = rs!MODEL
If rs!Type = "45" Then
Option1.Value = True
ElseIf rs!Type = "55" Then
Option2.Value = True
Else
Option2.Value = True
End If
pesan =
MsgBox("DATA SUDAH ADA... ^_^ ", vbInformation, " PERHATIAN")
Else
pesan =
MsgBox("DATA BELUM ADA... ^_^ ", vbInformation, "
PERHATIAN")
Text1.SetFocus
End If
End Sub
Private Sub
edit1_Click()
pesan_edit =
MsgBox("YAKIN MAU DIRUBAH...?", vbQuestion + vbYesNo,
"PELOKAN....")
If
pesan_edit = vbYes Then
luas_tanah = Text2.Text
model_rumah = Combo1
If Option1.Value = True Then
type_rumah = "45"
ElseIf Option2.Value = True Then
type_rumah = "55"
ElseIf Option3.Value = True Then
type_rumah = "70"
End If
sql = "
update tb_rumah set luas = '" & luas_tanah & "',type =
'" & type_rumah & "',model = '" & model_rumah &
"' where no_rmh = '" & Text1.Text & "'"
cn.Execute
sql
Text1 = ""
Text2 = ""
Combo1 = ""
Option1 = False
Option2 = False
Option3 = False
Else
Text2.SetFocus
End If
End Sub
Private Sub
hapus1_Click()
pesan_hapus
= MsgBox("YAKIN MAU DIHAPUS...???", vbQuestion + vbYesNo,
"HAPUS")
If pesan_hapus = vbYes Then
sql = "delete from tb_rumah
where no_rmh = '" & Text1.Text & "'"
cn.Execute sql
Text1.Text = ""
Text2.Text = ""cn
Combo1 = ""
Option1 = False
Option2 = False
Option3 = False
Else
Text1.SetFocus
End If
End Sub
Private Sub
keluar_Click()
Unload Me
End Sub