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

【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群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

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