Tai MDIForm
Private Sub MDIForm_Load()
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path +
"\qlxm.mdb;Persist Security Info=False"
cn.CursorLocation = adUseClient
End Sub
Private Sub mnintatcacachang_Click()
' khai bao recordset
Dim rs As New ADODB.Recordset
' lay ve tat ca cac hang
rs.Open "hang", cn
' dua du lieu vao Rhang
Set Rhang.DataSource = rs
Rhang.Show
' hien thi Rhang
End Sub
Private Sub mnintatcacacxe_Click()
' khai bao recordset
Dim rs As New ADODB.Recordset
' lay ve tat ca cac hang
rs.Open "xemay", cn
' dua du lieu vao Rxemay
Set RXemay.DataSource = rs
RXemay.Show
End Sub
Private Sub mntimgiavain_Click()
frmtimgia.Show
End Sub
Private Sub mntkvain_Click()
frmtimhang.Show
End Sub
Tai Form tim gia
Dim rs As New ADODB.Recordset
Private Sub cmdtk_Click()
Dim rs As New ADODB.Recordset
rs.Open "select*from xemay where gia>=" + txttu.Text + "and gia<=" + txtden.Text, cn
Set DataGrid1.DataSource = rs
End Sub
Private Sub Form_Load()
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open "select*from xemay", cn, 2, 3
Set DataGrid1.DataSource = rs
End Sub
Private Sub cmdluu_Click() Private Sub cmdphuchoi_Click()
rs.Requery rs.CancelBatch adAffectCurrent
DataGrid1.AllowAddNew = False End Sub
DataGrid1.AllowUpdate = False
DataGrid1.AllowArrows = False
End Sub
Private Sub cmdsua_Click()
DataGrid1.AllowUpdate = True
End Sub
Private Sub cmdthem_Click()
DataGrid1.AllowAddNew = True
DataGrid1.AllowUpdate = True
DataGrid1.AllowArrows = True
Datagrid1.refresh
End Sub
Private Sub cmdxoa_Click()
t = MsgBox("chac chac xoa xong", vbYesNo)
If t = vbYes Then
rs.Delete
End If
End Sub
Private Sub cmdIn_Click()
Dim rs As New ADODB.Recordset
rs.Open "select*from xemay where gia>=" + txttu.Text + "and gia<=" + txtden.Text, cn
Set RXemay.DataSource = rs
RXemay.Show
End Sub
Tai Form tim hang
Dim rs As New ADODB.Recordset
Private Sub cmdIn_Click()
Dim rs As New ADODB.Recordset
rs.Open "select*from hang,xemay where hang.mahang=xemay.mahang and
tenhang like '%" + txttk.Text + "%' ", cn
Set RXemay.DataSource = rs
RXemay.Show
End Sub
Private Sub Form_Load()
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open "select*from xemay", cn, 2, 3
Set DataGrid1.DataSource = rs
End Sub
Private Sub txttk_Change()
Dim rs As New ADODB.Recordset
rs.Open "select*from hang,xemay where hang.mahang=xemay.mahang and
tenhang like '%" + txttk.Text + "%' ", cn
Set DataGrid1.DataSource = rs
End Sub
Tại formtimmax
Private Sub Form_Load()
Dim rs As New ADODB.Recordset
rs.Open "xemay", cn
Dim tenxe, tenxemin As String
Max = 0: Min = 0: dem = 0
If Not rs.EOF Then
Min = rs.Fields("gia")
End If
Do While Not rs.EOF()
If Max < rs.Fields("gia") Then
Max = rs.Fields("gia")
tenxe = rs.Fields("tenxe")
End If
If Min > rs.Fields("gia") Then
Min = rs.Fields("gia")
tenxemin = rs.Fields("tenxe")
End If
dem = dem + rs.Fields("soluong")
rs.MoveNext
Loop
txtcn.Text = tenxe
Txttong.Text = dem
txttn.Text = tenxemin
End Sub
Tại form đếm c¸c h·ng xe(phải kết nối query trªn asscer)
Private Sub Form_Load()
Dim rs As New ADODB.Recordset
rs.Open "tk2", cn
Set DataGrid1.DataSource = rs
End Sub