面向初学者的窗体功能设计集成
时 间: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源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)
- 分享一下Access工程中的acw...(11.07)
- Access快速开发平台--让有权...(11.04)