【Access高效办公】自动行号+插入行+删除行的源码示例分享
时 间:2022-06-08 11:12:09
作 者:鼠标 ID:27902 城市:嘉定
摘 要:自动行号+插入行+删除行。
正 文:
感谢盟威软件提供的Access学习平台,还有《半夜罗》Access爱好者提供的经典案例,因使用到了这个功能,在半夜罗Access爱好者的基础案例 http://www.accessoft.com/article-show.asp?id=18358 上,对《自动行号,插入行,删除行》做了一个包装,方便应用的时候调用,分享给有需要的Access爱好者,存个档也方便以后自己查资料。
演示图:
示例下载:
模块代码:
'--------------------------------------------------------- '插入一行-------------------------------------------- 'form插入行所指定的窗体 'ctl序号控件的名称 'tmptbl插入行窗体所绑定的临时表 Function insertRow(Form As Form, ctl As Control, tmptbable As String) On Error Resume Next If Form.Dirty Then Form.Dirty = False If ctl.Value > 0 Then tmpSN = ctl.Value strSQL = "update " & tmptbable & " set " & ctl.Name & " = " & ctl.Name & "+1 where " & ctl.Name & ">=" & tmpSN CurrentDb.Execute strSQL strSQL = "insert into " & tmptbable & "(" & ctl.Name & ") values(" & tmpSN & ")" CurrentDb.Execute strSQL Form.Requery Form.Recordset.Move tmpSN - 1 '光标定位 End If End Function '删除一行---------------------------------------------------- 'form插入行所指定的窗体 'ctl序号控件的名称 'tmptbl插入行窗体所绑定的临时表 Function deleteRow(Form As Form, ctl As Control, tmpTable As String) On Error Resume Next If Form.Dirty Then Form.Dirty = False If ctl.Value > 0 Then tmpSN = ctl.Value strSQL = "Delete * FROM " & tmpTable & " Where " & ctl.Name & "=" & tmpSN CurrentDb.Execute strSQL strSQL = "Update " & tmpTable & " SET " & ctl.Name & " = " & ctl.Name & "-1 Where " & ctl.Name & ">=" & tmpSN CurrentDb.Execute strSQL Form.Requery Form.Recordset.Move tmpSN - 1 '光标定位 End If End Function '------------------------------------------------------------------------- '新增数据行自动获取当前行号,放在子窗体的插入前事件中 Function getRow(Form As Form, ctl As Control) ctl.Value = Form.CurrentRecord End Function
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access选项卡示例】Ac...(09.09)
- 【Access源码示例】按输入...(09.02)
- 【Access日期区间段查询】...(08.29)
- 【Access日期区间段查询】...(08.27)
- Access怎样才能实现日期时...(08.21)
- 【Access定时打开查询】A...(08.19)
- Access生成固定数量的记录...(08.13)
- Access怎样才能实现日期时...(08.12)
- Access利用导航窗体控件对...(08.03)
学习心得
最新文章
- Access表中的字段名、字段标题...(09.19)
- Access快速开发平台--更改“...(09.18)
- 【中秋及国庆优惠】Access培训...(09.15)
- Access如何将日期型的数值转换...(09.14)
- 英文输入法输入数据中存在单引号引起...(09.11)
- 【Access选项卡示例】Acce...(09.09)
- 让Access光标停留在指定的控件...(09.07)
- 关于Access查询条件里使用通配...(09.06)
- Access报表偷懒制作法--Ac...(09.05)
- Access快速开发平台--窗体数...(09.04)