Coding

Friday, June 01, 2007

Option Explicit Dim db As DAO.Database Dim rs As DAO.Recordset Private Sub cmdClose_Click() End End Sub Private Sub Form_Load() Set db = OpenDatabase("D:\2007-Semester2
\VB-RAD\Praktikum\Prak14-uts\pidel-97.mdb")
End Sub

Private Sub Form_Unload(Cancel As Integer)
db.Close
End Sub

Private Sub cmdViewData_Click()
Dim hasil As String
Dim i As Integer
Dim cek As Boolean

cek = False
If (chkSpe.Value = vbChecked) Then
If (IsNumeric(txtFrom.Text) = True) Then
If (IsNumeric(txtTo.Text) = True) Then
Set rs = db.OpenRecordset("SELECT * FROM mahasiswa WHERE NIM BETWEEN " & txtFrom.Text & " AND " & txtTo.Text, dbOpenDynaset)
cek = True
Else
MsgBox " Please enter numeric value", vbCritical, " Error"
txtTo.SetFocus
End If
Else
MsgBox " Please enter numeric value", vbCritical, " Error"
txtTo.SetFocus
End If

Else
Set rs = db.OpenRecordset("SELECT * FROM mahasiswa", dbOpenDynaset)
cek = True
End If

If (cek = True) Then
If rs.EOF = True Then
MsgBox "No Data Found", vbInformation, "Result"
Exit Sub
End If

i = 0
txtResult.Text = ""
Do
hasil = ""
i = i + 1
hasil = hasil & Format(i, "000") & " - " & rs!NIM & " - " & rs!Nama & " - " & rs!Alamat & " - "
txtResult.Text = txtResult.Text & hasil & vbCrLf
rs.MoveNext
Loop While Not rs.EOF

rs.Close
End If
End Sub



Regards

0 pengkoment...:

Post a Comment