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 "该数据表不能支持的游标模式", vbCritical, "不规则的格式": Exit Sub
End If
rs.PageSize = Text1.Text
rslen = rs.RecordCount
If rs.PageCount < page Then page = 1
Label3.Caption = "共" & rslen & "条记录,共" & rs.PageCount & "页,当前页码 " & 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 '根据字段指定视图列
c.AddItem ziduan(i).Name
rs.MoveFirst '记录到尾后填充下一列
rs.AbsolutePage = page '定义记录集的绝对页码
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 & "(会员名 Text,密码 Varchar(8),年龄 int not null,经验值 " & _
"integer,加入日期 DateTime null)"
link1.Execute "insert into 新建表" & str1 & "(会员名,密码,年龄,经验值,加入日期) values ('风云舞','12345678'" & _
",18,365,'" & Now & "')"
link1.Execute "insert into 新建表" & str1 & "(会员名,密码,年龄,经验值,加入日期) 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 & "第一行数据大小:" & _
str3 & vbCrLf & vbCrLf & "每行数据预设容量:" & str4, vbExclamation, "表属性"
End Select
End Sub
Private Sub Text2_GotFocus()
If Text2.Text = "查找关键字..." Then Text2.Text = ""
End Sub
Private Sub Text2_LostFocus()
If Text2.Text = "" Then Text2.Text = "查找关键字..."
End Sub
Private Sub up_Click() '功能,上一页
page = page - 1: list1_MouseUp 1, 0, 10, 10
End Sub(完)