|
无意中打开了切换面板的源代码,但许多看不懂,看懂了的就加了注释,哪位高手能补一补全啊
Option Compare Database
Private Sub Form_Open(Cancel As Integer)切换面板打开时的代码
' Minimize the database window and initialize the form.最小化数据库窗口和切换面板的初始化
' Move to the switchboard page that is marked as the default.切换面板移动到默认位置
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "窗体的筛选属性初始值:项目数为0,对正为默认值
Me.FilterOn = True筛选属性有效
End Sub
Private Sub Form_Current()窗体刷新时发生的程序代码
' Update the caption and fill in the list of options.更新名称和掩码
Me.Caption = Nz(Me![ItemText], "")窗体的名称为项目的名称,如果没有项目,通过NZ函数也不会出错
FillOptions调用掩码选项的函数
End Sub
Private Sub FillOptions()掩码选项的函数
' Fill in the options for this switchboard page.给切换面板设置掩码
' The number of buttons on the form.按钮的数目
Const conNumButtons = 8最大按钮数目为8
Dim con As Object
Dim rs As Object
Dim stSql As String
Dim intOption As Integer
' Set the focus to the first button on the form,将焦点移动到第一个按钮上
' and then hide all of the buttons on the form将全部按钮隐藏
' but the first. You can't hide the field with the focus.但第一个按钮除外,你不可能隐藏焦点控件
Me![Option1].SetFocus将焦点移动到第一个按钮上
For intOption = 2 To conNumButtons从第二个按钮开始到全部按钮
Me("Option" & intOption).Visible = False按钮不可见
Me("OptionLabel" & intOption).Visible = False按钮的说明文字也不可见
Next intOption
' Open the table of Switchboard Items, and find在切换面板上展开各个项目
' the first item for this Switchboard Page.
Set con = Application.CurrentProject.Connection给当前的联接对象命名,以便引用它
stSql = "SELECT * FROM [Switchboard Items]"设定SQL语句,一句写太长不好看,它分成三句写
stSql = stSql & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" & Me![SwitchboardID]
stSql = stSql & " ORDER BY [ItemNumber];"
Set rs = CreateObject("ADODB.Recordset")这个不知道是什么对象
rs.Open stSql, con, 1 ' 1 = adOpenKeyset这OPEN函数有三参数,什么意思懒得去看
' If there are no options for this Switchboard Page,如果切换面板上没有项目(按钮)
' display a message. Otherwise, fill the page with the items.显示项目并查找面板
If (rs.EOF) Then转换数据库代码
Me![OptionLabel1].Caption = "There are no items for this switchboard page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True按钮可见
Me("OptionLabel" & rs![ItemNumber]).Visible = True标签文字可见
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]标签文字为项目的标题
rs.MoveNext
Wend
End If
' Close the recordset and the database.将这两个数据对象关闭
rs.Close
Set rs = Nothing
Set con = Nothing
End Sub
Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.
' Constants for the commands that can be executed.
Const conCmdGotoSwitchboard = 1
Const conCmdOpenFormAdd = 2
Const conCmdOpenFormBrowse = 3
Const conCmdOpenReport = 4
Const conCmdCustomizeSwitchboard = 5
Const conCmdExitApplication = 6
Const conCmdRunMacro = 7
Const conCmdRunCode = 8
Const conCmdOpenPage = 9
' An error that is special cased.
Const conErrDoCmdCancelled = 2501
Dim con As Object
Dim rs As Object
Dim stSql As String
On Error GoTo HandleButtonClick_Err
' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
stSql = "SELECT * FROM [Switchboard Items] "
stSql = stSql & |
|