(7)为什么这些菜单可以调用这些子窗体或者执行退出主窗体的操作呢?在图10.50的主窗体中用鼠标双击,在出现的代码窗口中的主要代码如下。 ――――――――――――――――――――――――――――――――――――― ‘选择菜单项DirectorInsertMenu后将显示子窗体FormInsertDirector PRivate Sub DirectorInsertMenu_Click() FormInsertDirector.Show End Sub ‘选择菜单项DirectorSelectMenu 后将显示子窗体FormSelectDirector Private Sub DirectorSelectMenu_Click() FormSelectDirector.Show End Sub ‘选择菜单项DirectorUpdateMenu后将显示子窗体FormUpdateDirector Private Sub DirectorUpdateMenu_Click() FormUpdateDirector.Show End Sub ‘选择菜单项GraduateInsertMenu后将显示子窗体FormInsertGraduate Private Sub GraduateInsertMenu_Click() FormInsertGraduate.Show End Sub ‘选择菜单项GraduateSelectMenu后将显示子窗体FormSelectGraduate Private Sub GraduateSelectMenu_Click() FormSelectGraduate.Show End Sub ‘选择菜单项GraduateUpdateMenu后将显示子窗体FormUpdateGraduate Private Sub GraduateUpdateMenu_Click() FormUpdateGraduate.Show End Sub ‘选择菜单项MajorInsertMenu后将显示子窗体FormInsertMajor Private Sub MajorInsertMenu_Click() FormInsertMajor.Show End Sub ‘选择菜单项MajorUpdateMenu后将显示子窗体FormUpdateMajor Private Sub MajorUpdateMenu_Click() FormUpdateMajor.Show End Sub ‘选择菜单项ExitMenu后将显示退出主窗体 Private Sub ExitMenu_Click() End End Sub ―――――――――――――――――――――――――――――――――――――
模块的设计
模块Module1的其他主要代码如下。 ――――――――――――――――――――――――――――――――――――― ‘定义了名为ConnectString的无参数函数,连接数据库 Public Function ConnectString() As String ConnectString = "DSN=graduateDB;UID=graduateuser;PWD=12345678" End Function ‘定义了名为ExecuteSQL的带参数函数,参数SQL和MsgString都为字符串型。该函数用于执行SQL语句。 Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset ‘conn为ADODB的connection连接对象 Dim conn As ADODB.Connection ‘rest为ADODB的记录集对象 Dim rest As ADODB.Recordset ‘若执行SQL错误转向ExecuteSQL_Error标记处 On Error GoTo ExecuteSQL_Error Set conn = New ADODB.Connection ‘连接数据库 conn.Open ConnectString Set rest = New ADODB.Recordset ‘执行SQL字符串语句 rest.Open Trim$(SQL), conn, adOpenKeyset, adLockOptimistic Set ExecuteSQL = rest MsgString = "查询到" & rest.RecordCount & " 条记录" ‘执行SQL完毕后关闭连接和记录集 ExecuteSQL_Exit: Set rest = Nothing Set conn = Nothing Exit Function ‘执行SQL错误时的处理方法 ExecuteSQL_Error: MsgString = "查询错误: " & _ Err.Description Resume ExecuteSQL_Exit End Function ‘定义了名为Checktxt的带参数函数,参数txt为字符串型。该函数用于检测txt字符串是否有内容。 Public Function Checktxt(txt As String) As Boolean If Trim(txt) = "" Then Checktxt = False Else Checktxt = True End If End Function ――――――――――――――――――――――――――――――――――――― 各子窗体的设计