Private Sub Form_Unload(Cancel As Integer)
If rs.State = 1 Then rs.Close
If link1.State = 1 Then link1.Close
Set rs = Nothing: Set link1 = Nothing
End Sub
Private Sub list1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) '切換表
On Error Resume Next
If list1.ListItems.Count = 0 Then Exit Sub
If rs.State = 1 Then rs.Close
list2.ListItems.Clear: list2.ColumnHeaders.Clear: c.Clear
rs.Open "select * from " & list1.SelectedItem.Text, link1, adOpenStatic, adLockReadOnly
If Err.Number <> 0 Then
MsgBox "該數(shù)據(jù)表不能支持的游標(biāo)模式", vbCritical, "不規(guī)則的格式": Exit Sub
End If
rs.PageSize = Text1.Text
rslen = rs.RecordCount
If rs.PageCount < page Then page = 1
Label3.Caption = "共" & rslen & "條記錄,共" & rs.PageCount & "頁(yè),當(dāng)前頁(yè)碼 " & page
If rs.PageCount > page Then down.Enabled = True Else down.Enabled = False
If page <> 1 Then up.Enabled = True Else up.Enabled = False
Set ziduan = rs.Fields '定義字段記錄集
For i = 0 To ziduan.Count - 1
list2.ColumnHeaders.Add , , ziduan(i).Name '根據(jù)字段指定視圖列
c.AddItem ziduan(i).Name
rs.MoveFirst '記錄到尾后填充下一列
rs.AbsolutePage = page '定義記錄集的絕對(duì)頁(yè)碼
For r = 0 To rs.PageSize - 1
If rs.EOF Then Exit For
rstext = rs(i)
If i = 0 Then '首次直接填充第一列
list2.ListItems.Add , , rstext
Else '非首次填充下一下
If rstext <> Empty Then list2.ListItems(r + 1).ListSubItems.Add , , rstext Else list2.ListItems(r + 1).ListSubItems.Add , , ""
End If
rs.MoveNext
Next
Next
If c.ListCount <> 0 Then c.ListIndex = 0: findstr.Enabled = True Else findstr.Enabled = False
Set ziduan = Nothing
End Sub
Private Sub menu01_Click(Index As Integer)
Select Case Index
Case 1: '建新表演示
str1 = 1
For i = 1 To list1.ListItems.Count
If InStr(list1.ListItems(i).Text, "新建表") = 1 Then str1 = str1 + 1
Next
link1.Execute "create table 新建表" & str1 & "(會(huì)員名 Text,密碼 Varchar(8),年齡 int not null,經(jīng)驗(yàn)值 " & _
"integer,加入日期 DateTime null)"
link1.Execute "insert into 新建表" & str1 & "(會(huì)員名,密碼,年齡,經(jīng)驗(yàn)值,加入日期) values ('風(fēng)云舞','12345678'" & _
",18,365,'" & Now & "')"
link1.Execute "insert into 新建表" & str1 & "(會(huì)員名,密碼,年齡,經(jīng)驗(yàn)值,加入日期) values ('Lshdic','87654321'" & _
",18,365,'" & Now & "')"
opendatabase pubdatapath '刷新重裝載列表
Case 2: '刷新——重裝載
opendatabase pubdatapath
Case 3: '刪除
If rs.State = 1 Then rs.Close
link1.Execute "Drop table " & list1.SelectedItem.Text
opendatabase pubdatapath
Case 4: '表屬性
If rs.State = 1 Then rs.Close
rs.Open "select * from " & list1.SelectedItem.Text, link1, adOpenStatic, adLockReadOnly
For i = 0 To rs.Fields.Count - 1
str1 = str1 & rs.Fields(i).Name & ","
str2 = str2 & rs.Fields(i).Type & ","
str3 = str3 & rs.Fields(i).ActualSize & ","
str4 = str4 & rs.Fields(i).DefinedSize & ","
Next
MsgBox "包含字段:" & str1 & vbCrLf & vbCrLf & "字段類型:" & str2 & vbCrLf & vbCrLf & "第一行數(shù)據(jù)大小:" & _
str3 & vbCrLf & vbCrLf & "每行數(shù)據(jù)預(yù)設(shè)容量:" & str4, vbExclamation, "表屬性"
End Select
End Sub
Private Sub Text2_GotFocus()
If Text2.Text = "查找關(guān)鍵字..." Then Text2.Text = ""
End Sub
Private Sub Text2_LostFocus()
If Text2.Text = "" Then Text2.Text = "查找關(guān)鍵字..."
End Sub
Private Sub up_Click() '功能,上一頁(yè)
page = page - 1: list1_MouseUp 1, 0, 10, 10
End Sub(完)