【正文】
!, vbOKOnly + vbExclamation, 警告 ! End If End Sub Private Sub xuefeishezhi_Click() End Sub 4. 3 檔案管理 4. 3. 1 檔案瀏覽 圖 檔案瀏覽 設(shè)計過程: 用控件可以實現(xiàn)檔案的瀏覽,在此窗體所有上用戶可以瀏覽,查找,有權(quán)限的用戶可以進行修改和刪除。此窗體與數(shù)據(jù)輪中的 student 表進行連接。 設(shè)計代碼: Private Sub Command1_Click() 13 End Sub Private Sub Command2_Click() If QX2 = True Then Else MsgBox 對不起 ,您沒有權(quán)限 !, vbOKOnly + vbExclamation, 警告 ! End If End Sub Private Sub Command3_Click() If QX2 = True Then 39。刪除語句 If MsgBox(確定要刪除學號為 amp。 !學號 amp。 的記錄么? amp。 Chr(10) + Chr(13) amp。 會導致該學生的信息丟失 ! amp。 Chr(10) + Chr(13) amp。 確定么 ?, vbYesNo + vbExclamation, 警告 ) = vbYes Then If MsgBox(真的要刪除么? , vbYesNo + vbExclamation, 警告! ) = vbYes Then MsgBox 刪除成功! , vbOKOnly + vbInformation, 提示! End If End If Else MsgBox 對不起 ,您沒有權(quán)限 !, vbOKOnly + vbExclamation, 警告 ! End If End Sub Private Sub Command4_Click() Unload Me End Sub Private Sub Form_Load() 39。打開數(shù)據(jù)庫中的 student 表 OpenTable Adodc1, student 39。連接 DataGrid1 表到數(shù)據(jù)庫 Set = Adodc1 End Sub 14 4. 3. 2 檔案添加 圖 檔案登記 設(shè)計過程: 用于檔案 的登記,此窗體和檔案瀏覽窗體中的數(shù)據(jù)表進行了連接,可以直接進行添加,前提是必須有權(quán)限,加入了 text 和 bo 控件的 keypress事件,讓用戶可以更輕松的進行添加。 設(shè)計代碼: Private Sub bo1_KeyPress(KeyAscii As Integer) 39?;剀嚀Q下一個輸入項目 If KeyAscii = 13 Then SendKeys {TAB} End If End Sub Private Sub bo2_KeyPress(KeyAscii As Integer) 39。回車換下一個輸入項目 If KeyAscii = 13 Then 15 SendKeys {TAB} End If End Sub Private Sub Command1_Click() 39。定義變量 Dim msg Dim f As Boolean Dim g As Boolean Dim j As Integer f = True g = True 39。判斷文本框是否為空 For j = 0 To 4 If Text1(j).Text = Then MsgBox Label2(j).Caption amp。 不能為空 ! , vbExclamation + vbOKOnly, 警告 f = False Text1(j).SetFocus Exit Sub End If Next j 39。判斷出生年月是否為日期 If Not IsDate(Text1(2).Text) Then MsgBox 應(yīng)輸入日期 yymmdd, vbOKOnly + vbInformation, 提示 g = False 39。反白錯誤的框 Text1(2).SetFocus Text1(2).SelStart = 0 Text1(2).SelLength = 10 Exit Sub End If 39。判斷入學時間是否為日期 If Not IsDate(Text1(4).Text) Then MsgBox 應(yīng)輸入日期 yymmdd, vbOKOnly + vbInformation, 提示 g = False 39。反白錯誤的框 Text1(4).SetFocus Text1(4).SelStart = 0 16 Text1(4).SelLength = 10 End If 39。判斷是否要保存 If f = True And g = True Then msg = MsgBox(確定要添加么? , vbYesNo + vbInformation, 提示 ) End If 39。確定后執(zhí)行的語句 If msg = vbYes Then MsgBox 添加成功! , vbOKOnly + vbInformation, 提示 39。數(shù)據(jù)傳遞到數(shù)據(jù)庫 !學號 = Text1(0).Text !姓名 = Text1(1).Text !出生年月 = Text1(2).Text !家庭住址 = Text1(3).Text !入學時間 = Text1(4).Text !備注 = Text1(5).Text !性別 = !班級 = 39。添加保存后清空文本 For j = 0 To 5 Text1(j).Text = Next j End If End Sub Private Sub Command2_Click() 39。退出該窗體 Unload Me End Sub Private Sub Form_Load() 39。打開數(shù)據(jù)庫中的 student 表 OpenTable Adodc1, student 39。初始化 bo 的初值 = (ListIndex) = (ListIndex) 17 End Sub Private Sub text1_KeyPress(Index As Integer, KeyAscii As Integer) 39。回車換下一個輸入項目 If KeyAscii = 13 Then SendKeys {TAB} End If End Sub Private Sub Form_Activate() Text1(0).SetFocus End Sub 4. 3. 3檔案查詢 圖 學生信息查找 設(shè)計過程: 用戶可以根據(jù)自己的需要按學號,姓名,班級查找,查找的學生信息會顯示在檔案瀏覽的窗體上,用的是 sql語言。在此窗體上必須輸入至少一條記錄,不然會提示。若沒 18 有找到一條符合的記錄,則會提示無此記錄。 設(shè)計代碼: Private Sub Command1_Click() 39。定義 sql語言 Dim sqlxuehao As String Dim sqlxingming As String Dim sqlbanji As String sqlxuehao = select * from student where 學號 =39。 amp。 amp。 39。 sqlxingming = select * from student where 姓名 =39。 amp。 amp。 39。 sqlbanji = select * from student where 班級 =39。 amp。 amp。 39。 If = And = And = Then = 至少一條記錄不空 Exit Sub End If If Then = sqlxuehao End If If Then = sqlxingming End If If Then = sqlbanji End If If Then MsgBox 無此記錄 , vbOKOnly + vbInformation, 提示 End If Unload Me End Sub Private Sub Command2_Click() 39。退出該窗體 19 Unload Me End Sub Private Sub Form_Activate() End Sub Private Sub bo1_KeyPress(KeyAscii As Integer) 39?;剀嚀Q下一個輸入項目 If KeyAscii = 13 Then SendKeys {TAB} End If End Sub Private Sub text1_KeyPress(KeyAscii As Integer) 39?;剀嚀Q下一個輸入項目 If KeyAscii = 13 Then SendKeys {TAB} End If End Sub Private Sub text2_KeyPress(KeyAscii As Integer) 39?;剀嚀Q下一個輸入項目 If KeyAscii = 13 Then SendKeys {TAB} End If End Sub 20 4. 4 成績管理 4. 4. 1 成績?yōu)g覽與修改 圖 考試成績?yōu)g覽 設(shè)計過程: 通過一個 bo 數(shù)組( 4個),來實現(xiàn)各個信息的選擇,符合的信息會在下面顯示出來,同時此窗體同樣可以連接到其它的窗體上,例如修改。若是有權(quán)限的話還可以直接刪除。此窗體是連接到數(shù)據(jù)庫中的 scorei表。 設(shè)計代碼: Private Sub Command1_Click() If QX4 = True Then flAg = False Else MsgBox 對不起 ,您沒有權(quán)限 !, vbOKOnly + vbExclamation, 警告 ! End If End Sub 21 Private Sub Command2_Click() If QX4 = True Then 39。刪除語句 If MsgBox(確定要刪除學號為 amp。 !學號 amp。 的記錄么? amp。 Chr(10) + Chr(13) amp。 會導致該學生的信息丟失 ! amp。 Chr(10) + Chr(13) amp。 確定么 ?, vbYesNo + vbExclamation, 警告 ) = vbYes Then If MsgBox(真的要刪除么? , vbYesNo + vbExclamation, 警告! ) = vbYes Then MsgBox 刪除成功! , vbOKOnly + vbInformation, 提示! End If End If Else MsgBox 對不起 ,您沒有權(quán)限 !, vbOKOnly + vbExclamation, 警告 ! End If End Sub Private Sub Command3_Click() 39。定義 sql語言 Dim sqlxuwqi As String Dim sqlleixing As String sqlxuwqi = select * from score where 學期 =39。 amp。 Combo1(2).Text amp。 39。 sqlleixing = select * from score where 類型 =39。 amp。 Combo1(3).Text amp。 39。 = sqlxuwqi = sqlleixing If Then MsgBox 無此記錄 , vbOKOnl