End If End Sub
„--------------------------------------------------------------------------------------------
Private Sub cmdend_Click() Unload Me
End Sub
„--------------------------------------------------------------------------------------------
Private Sub Cmdfind_Click()
If Cmdfind.Caption = "T×m" Then txtlop.Text = ""
txtnvt.Text = "" txtss.Text = ""
Cmdfind.Caption = "HiÓn thÞ" txtlop.SetFocus
Else rs.MoveFirst
rs.Find "tenlop='" & Trim(txtlop.Text) & "'" If rs.EOF Then
MsgBox "Kh«ng t×m thÊy " Else
Call display End If
Cmdfind.Caption = "T×m" End If
End Sub
„--------------------------------------------------------------------------------------------
Private Sub cmdfirst_Click()
If rs.RecordCount > 0 Then rs.MoveFirst
Call display End If
End Sub
„--------------------------------------------------------------------------------------------
Private Sub cmdlast_Click()
If rs.RecordCount > 0 Then rs.MoveLast
Call display
End If End Sub
„--------------------------------------------------------------------------------------------
Private Sub cmdnext_Click()
If rs.RecordCount > 0 Then rs.MoveNext
If rs.EOF Then
MsgBox "B¹n ®ang ë b¶n ghi cuèi cïng" Else
Call display End If
End If End Sub
„--------------------------------------------------------------------------------------------
Private Sub cmdpre_Click()
If rs.RecordCount > 0 Then rs.MovePrevious
If rs.BOF Then
MsgBox "B¹n ®ang ë b¶n ghi ®Çu tiªn" Else
Call display End If
End If End Sub
„--------------------------------------------------------------------------------------------
Private Sub cmdupdate_Click()
If cmdupdate.Caption = "Söa" Then cmdupdate.Caption = "Ghi"
Else
rs.save Call save
End If End Sub
dcbma
txttien
txtnnop
txtnd
DataGrid
Bước 10. Thiết kế form frmhpsv.frm và đặt tên cho các điều khiển theo chỉ dẫn
cmdpre | cmdnext | cmdlast |
Có thể bạn quan tâm!
- Tạo Trình Thiết Kế Môi Trường Dữ Liệu Sử Dụng Data View
- Lập trình Window - 26
- Lập trình Window - 27
- Trình Đóng Gói Và Triển Khai Ứng Dụng
- Lập trình Window - 30
- Lập trình Window - 31
Xem toàn bộ 248 trang tài liệu này.
cmddel | cmdfind | cmdupdate | cmdend |
Bước 11. Mở cửa sổ Code của form frmhpsv.frm và nhập vào các dòng lệnh sau:
Dim Cnn As New ADODB.Connection Dim rs As New ADODB.Recordset
Public Sub display() dcbma.Text = rs!masv txtnnop.Text = rs!ngaynop txtnd.Text = rs!noidung txttien = rs!sotien
End Sub
„------------------------------------------------------------------------------------
Public Sub save() rs!noidung = txtnd.Text
rs!ngaynop = CDate(txtnnop.Text) rs!masv = dcbma.BoundText rs!sotien = Val(txttien.Text) rs.Update
End Sub
„------------------------------------------------------------------------------------
Public Sub luoi()
'hien thi cac lan nop hjoc phi Dim x As String
x = "select * from hocphi where masv='" & Text1.Text & "'" Dim rsxem As New ADODB.Recordset rsxem.CursorLocation = adUseClient
rsxem.Open x, Cnn, adOpenStatic, adLockReadOnly Set DataGrid1.DataSource = rsxem
End Sub
„----------------------------------------------------------------------------------------------
Private Sub cmdadd_Click()
If cmdadd.Caption = "Bæ sung" Then txtnd.Text = ""
txttien.Text = "" txtnnop.Text = "" dcbma.Text = "" cmdadd.Caption = "Ghi" dcbma.SetFocus
Else
rs.AddNew Call save
cmdadd.Caption = "Bæ sung" End If
End Sub
„----------------------------------------------------------------------------------------------
Private Sub cmddel_Click() rs.Delete
If Not rs.EOF Then Call cmdnext_Click
Else
Call cmdfirst_Click End If
End Sub
„------------------------------------------------------------------------------------
Private Sub cmdend_Click() Unload Me
End Sub
„----------------------------------------------------------------------------------------------
Private Sub Cmdfind_Click()
If Cmdfind.Caption = "T×m" Then txtnd.Text = ""
txttien.Text = "" txtnnop.Text = "" dcbma.Text = ""
Cmdfind.Caption = "HiÓn thÞ" dcbma.SetFocus
Else
Dim x As String
x = "select * from hocphi where masv='" & dcbma.Text & "'" Dim rsxem As New ADODB.Recordset rsxem.CursorLocation = adUseClient
rsxem.Open x, Cnn, adOpenStatic, adLockReadOnly Set DataGrid1.DataSource = rsxem Cmdfind.Caption = "T×m"
End If End Sub
„----------------------------------------------------------------------------------------------
Private Sub cmdfirst_Click()
If rs.RecordCount > 0 Then rs.MoveFirst
Call display End If
End Sub
„----------------------------------------------------------------------------------------------
Private Sub cmdlast_Click()
If rs.RecordCount > 0 Then rs.MoveLast
Call display End If
End Sub
„----------------------------------------------------------------------------------------------
Private Sub cmdnext_Click() If rs.RecordCount > 0 Then
rs.MoveNext
If rs.EOF Then
MsgBox "B¹n ®ang ë b¶n ghi cuèi cïng" Else
All display End If
End If End Sub
„----------------------------------------------------------------------------------------------
Private Sub cmdpre_Click()
If rs.RecordCount > 0 Then rs.MovePrevious
If rs.BOF Then
MsgBox "B¹n ®ang ë b¶n ghi ®Çu tiªn" Else
Call display End If
End If End Sub
„----------------------------------------------------------------------------------------------
Private Sub cmdupdate_Click()
If cmdupdate.Caption = "Söa" Then cmdupdate.Caption = "Ghi"
Else
rs.save Call save
End If End Sub
„----------------------------------------------------------------------------------------------
Private Sub dcbma_Click(Area As Integer)
Dim x As String
x = "select * from hocphi where masv='" & dcbma.Text & "'" Dim rsxem As New ADODB.Recordset rsxem.CursorLocation = adUseClient
rsxem.Open x, Cnn, adOpenStatic, adLockReadOnly Set DataGrid1.DataSource = rsxem
End Sub
„----------------------------------------------------------------------------------------------
Private Sub Form_Load()
Cnn.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source= " & App.Path & "qlhp.mdb"
Cnn.Open
'dua danh sach sinh vien vao Datacombo dcbma Dim rs1 As New ADODB.Recordset rs1.CursorLocation = adUseClient
rs1.Open "sinhvien", Cnn, adOpenStatic, adLockReadOnly Set dcbma.RowSource = rs1
dcbma.ListField = "masv" 'hien ra de chon dcbma.BoundColumn = "masv" 'cai can lay ra 'mo recordset rs de ghi du lieu vao bang sinh vien rs.CursorLocation = adUseClient
rs.Open "hocphi", Cnn, adOpenStatic, adLockOptimistic Call cmdfirst_Click
End Sub
Bước 12. Thiết kế form frmhp.frm và đặt tên cho các điều khiển theo chỉ dẫn
dcbma
dcbhk
DataGrid1
cmdend
cmdprint
Bước 13. Mở cửa sổ Code của form và nhập vào các dòng lệnh
Dim Cnn As New ADODB.Connection Dim rs As New ADODB.Recordset
Private Sub cmdend_Click() Unload Me
End Sub
„-----------------------------------------------------------------------------------------------
Private Sub cmdprint_Click()
x = "select distinct hoten, sophieu,hocphi.masv, ngaynop, sotien, noidung " _ & " from hocphi,sinhvien where (hocphi.masv=sinhvien.masv) and (" _
& " hocphi.masv ='" & dcbma.Text & "') and (noidung= '" & dcbhk.Text & "')"
Dim rshk As New ADODB.Recordset rshk.CursorLocation = adUseClient
rshk.Open x, Cnn, adOpenStatic, adLockReadOnly Set bienlai.DataSource = rshk
bienlai.Show End Sub
„-----------------------------------------------------------------------------------------------
Private Sub dcbhk_Click(Area As Integer)
x = "select distinct hocphi.masv, hocphi.ngaynop, hocphi.sotien, hocphi.noidun " _ & " from hocphi,sinhvien where (hocphi.masv=sinhvien.masv) and (" _
& " hocphi.masv ='" & dcbma.Text & "') and (noidung= '" & dcbhk.Text & "')"
Dim rshk As New ADODB.Recordset
rshk.CursorLocation = adUseClient
rshk.Open x, Cnn, adOpenStatic, adLockReadOnly Set DataGrid1.DataSource = rsh
End Sub
„-----------------------------------------------------------------------------------------------
Private Sub dcbma_Click(Area As Integer)
Dim x As String
x = "select * from hocphi where masv='" & dcbma.Text & "'"
Dim rsma As New ADODB.Recordset rsma.CursorLocation = adUseClient
rsma.Open x, Cnn, adOpenStatic, adLockReadOnly Set DataGrid1.DataSource = rsma
dcbhk.Text = "" End Sub
„-----------------------------------------------------------------------------------------------
Private Sub Form_Load()
Cnn.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source= " & App.Path & "qlhp.mdb"
Cnn.Open
'dua danh sach sinh vien vao Datacombo dcbma