easyui的textbox实现编辑保存_第80讲:工作表数据与UserForm窗口的交互,记录的编辑和保存...
大家好,我們今天繼續(xù)講解VBA數(shù)據(jù)庫解決方案,今日講解的是第80講:工作表數(shù)據(jù)與UserForm窗口的交互過程中:如何對顯示的記錄進行編輯和保存。在前幾講中,我們實現(xiàn)了將工作表的數(shù)據(jù)傳給UserForm窗口,實現(xiàn)的開始記錄、下一條記錄最后記錄的顯示,我們今日繼續(xù)講解如何實現(xiàn)編輯和保存記錄。前幾講是查找與顯示,查找的目的是為了編輯。
思路:①在UserForm窗口上,設(shè)置顯示編輯和保存按鈕,用于指令的下達。
②在彈出UserForm窗口后,EXCEL文件要隱藏。
③要考慮到按鈕之間的作用,此按鈕要在開始按鈕按過之后才可以響應動作。同時窗口上可以顯示的按鈕還有"顯示下一條記錄"和"顯示最后記錄"按鈕
下面我們首先實現(xiàn)UserForm窗體:在上一講的基礎(chǔ)上我這次增加的是"編輯"和"保存"按鈕:
下面看代碼的實現(xiàn):
1 從EXCEL窗口進入人機交互窗口:
Sub mynzRecords_80() '將工作表數(shù)據(jù)變成記錄集,并實現(xiàn)編輯和保存
Application.Visible = False
UserForm1.Show
End Sub
代碼解釋:上述代碼完成從EXCEL界面到人機交互UserForm窗體,這時的Application.Caller是5.
2 窗體加載時設(shè)置相關(guān)的屬性代碼:If Right(Application.Caller, 1) = 5 Then '顯示編輯記錄
UserForm1.CommandButton1.Enabled = False '下一條記錄
UserForm1.CommandButton4.Enabled = False '最后一條記錄
UserForm1.CommandButton5.Enabled = False '編輯記錄
UserForm1.CommandButton7.Enabled = False '查找記錄
UserForm1.CommandButton8.Enabled = False '刪除記錄
UserForm1.CommandButton6.Enabled = False '保存記錄
UserForm1.CommandButton9.Enabled = False '錄入記錄
UserForm1.TextBox1.Enabled = False
UserForm1.TextBox2.Enabled = False
UserForm1.TextBox3.Enabled = False
End If
代碼解釋:上述代碼設(shè)置了各個按鈕的必要屬性,大家要注意,由于涉及到保存記錄,這里的TextBox 的Enabled屬性設(shè)置為False.
3 "編輯"按鈕響應代碼:
Private Sub CommandButton5_Click() '編輯
MsgBox ("請修改記錄!")
UserForm1.TextBox2.Enabled = True
UserForm1.TextBox3.Enabled = True
UserForm1.CommandButton6.Enabled = True '保存記錄
End Sub
代碼解釋: 點擊"編輯"按鈕后彈出對話框,要求和用戶確認,得到認可后把TextBox2.Enabled,TextBox3.Enabled, CommandButton6.Enabled的屬性修改為True,這時就用戶可以編輯了與保存了。
4 "保存"按鈕響應代碼:
Private Sub CommandButton6_Click() '保存
If UserForm1.TextBox1.Value = "" Or UserForm1.TextBox2.Value = "" Or UserForm1.TextBox3.Value = "" Then MsgBox "信息有空值,請確認!": Exit Sub
If MsgBox("是否要保存記錄?
總結(jié)
以上是生活随笔為你收集整理的easyui的textbox实现编辑保存_第80讲:工作表数据与UserForm窗口的交互,记录的编辑和保存...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 交际过程的两个基本环节_跨文化交际学概论
- 下一篇: 河南招教考试计算机专业知识,河南教师招聘