Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-窗体/数据页

面向初学者的窗体功能设计集成

时 间:2009-11-30 08:43:54
作 者:todaynew   ID:1445  城市:上海
摘 要:面向初学者的窗体功能设计集成
正 文:


1、加载时,使用子窗体1,学生表全部记录,锁定主窗体和子窗体记录,配置按钮。

Private Sub Form_Load()
Dim sql As String
Me.子窗体.SourceObject = "子窗体1"
sql = "select * from 学生表"
Me.班级ID.Locked = True
Me.班级名称.Locked = True
Me.子窗体.Form.RecordSource = sql
Me.子窗体.Form.AllowAdditions = False
Me.子窗体.Form.AllowDeletions = False
Me.子窗体.Form.AllowEdits = False
Me.隐藏列.Visible = False
Me.展开列.Visible = False
Me.隐藏行.Visible = False
Me.展开行.Visible = False
End Sub


2、关闭窗体时,压缩并修复数据库。

Private Sub Form_Close()
'压缩和修复数据库
CommandBars("Tools").Controls("数据库实用工具(&D)").Controls("压缩和修复数据库(&C)...").accDoDefaultAction
End Sub


3、双击班级ID或班级名称时,解锁。

Private Sub 班级ID_DblClick(Cancel As Integer)
Me.班级ID.Locked = False
End Sub


Private Sub 班级名称_DblClick(Cancel As Integer)
Me.班级名称.Locked = False
End Sub


4、失去焦点时,锁定班级ID或班级名称。

Private Sub 班级ID_LostFocus()
Me.班级ID.Locked = True
End Sub


Private Sub 班级名称_LostFocus()
Me.班级名称.Locked = True
End Sub


5、单击时,使用字窗体1或子窗体2。


Private Sub 更换窗体1_Click()
Me.子窗体.SourceObject = "子窗体1"
Me.隐藏列.Visible = True
Me.展开列.Visible = True
Me.隐藏行.Visible = True
Me.展开行.Visible = True
Me.新增.Visible = True
Me.删除.Visible = True
End Sub


Private Sub 更换窗体2_Click()
Me.子窗体.SourceObject = "子窗体2"
Me.隐藏列.Visible = False
Me.展开列.Visible = False
Me.隐藏行.Visible = False
Me.展开行.Visible = False
Me.新增.Visible = False
Me.删除.Visible = False
End Sub


6、单击时,显示或者隐藏子窗体。

Private Sub 隐藏窗体_Click()
Me.子窗体.Visible = False
End Sub


Private Sub 显示窗体_Click()
Me.子窗体.Visible = True
End Sub

7、单击时,显示或隐藏按钮。

Private Sub 隐藏按钮_Click()
Me.隐藏列.Visible = False
Me.展开列.Visible = False
Me.隐藏行.Visible = False
Me.展开行.Visible = False
End Sub


Private Sub 显示按钮_Click()
Me.隐藏列.Visible = True
Me.展开列.Visible = True
Me.隐藏行.Visible = True
Me.展开行.Visible = True
End Sub


8、单击时,自动编号并新增记录。

Private Sub 新增_Click()
Dim sql As String
DoCmd.SetWarnings no
sql = "Insert INTO 学生表 ( 班级ID, 学生ID ) "
sql = sql + "Select Right(Forms!主窗体!班级ID,1) AS 班级ID, IIf(Max([学生ID]) Is Null,Forms!主窗体!班级ID & '01',Format(Max([学生ID])+1,'000')) AS ID "
sql = sql + "FROM 学生表 Where 学生表.班级ID=Forms!主窗体!班级ID;"
DoCmd.RunSQL sql
Me.子窗体.Requery
End Sub


9、单击时,删除指定记录。

Private Sub 删除_Click()
DoCmd.SetWarnings no
DoCmd.RunSQL "Delete * FROM 学生表 Where 删除=Yes;"
Me.子窗体.Requery
End Sub

10、单击时,锁定、解锁、刷新子窗体。

Private Sub 锁定_Click()
Me.子窗体.Form.AllowAdditions = False
Me.子窗体.Form.AllowDeletions = False
Me.子窗体.Form.AllowEdits = False
End Sub


Private Sub 解锁_Click()
Me.子窗体.Form.AllowAdditions = True
Me.子窗体.Form.AllowDeletions = True
Me.子窗体.Form.AllowEdits = True
End Sub


Private Sub 刷新_Click()
Me.子窗体.Requery
End Sub


11、单击时,隐藏或展开列。

Private Sub 隐藏列_Click()
Me.子窗体.Form.家庭住址.ColumnHidden = True
Me.子窗体.Form.联系电话.ColumnHidden = True
End Sub

Private Sub 展开列_Click()
Me.子窗体.Form.家庭住址.ColumnHidden = False
Me.子窗体.Form.联系电话.ColumnHidden = False
End Sub


12、单击时,隐藏或展开行。


Private Sub 隐藏行_Click()
Dim sql As String
sql = "select * from 学生表 where isnull(姓名)"
Me.子窗体.Form.RecordSource = sql
Me.子窗体.Requery
End Sub


Private Sub 展开行_Click()
Dim sql As String
sql = "select * from 学生表"
Me.子窗体.Form.RecordSource = sql
Me.子窗体.Requery
End Sub

 


点击下载此附件

 

欢迎加入AccessQQ群交流学习 群号:93390997



Access软件网QQ交流群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助