新增替换删除模块的部分代码的函数
时 间:2016-12-19 12:43:28
作 者:MDZZ ID:47512 城市:南京
摘 要:新增替换删除模块的部分代码
正 文:
给大家分享模块里面新增替换删除代码的函数
调用示例 Call InsertWholeLine("Module1", "Const conPi = 3.14", "Const conPi = 3.33")
Function DeleteWholeLine(strModuleName, strText As String) _ As Boolean Dim mdl As Module, lngNumLines As Long Dim lngSLine As Long, lngSCol As Long Dim lngELine As Long, lngECol As Long Dim strTemp As String On Error GoTo Error_DeleteWholeLine DoCmd.OpenModule strModuleName Set mdl = Modules(strModuleName) If mdl.Find(strText, lngSLine, lngSCol, lngELine, lngECol) Then lngNumLines = Abs(lngELine - lngSLine) + 1 strTemp = LTrim$(mdl.Lines(lngSLine, lngNumLines)) strTemp = RTrim$(strTemp) If strTemp = strText Then mdl.DeleteLines lngSLine, lngNumLines Else MsgBox "Line contains text in addition to '" _ & strText & "'." End If Else MsgBox "内容 '" & strText & "' 未找到." End If DeleteWholeLine = True Exit_DeleteWholeLine: Exit Function Error_DeleteWholeLine: MsgBox Err & " :" & Err.Description DeleteWholeLine = False Resume Exit_DeleteWholeLine End Function
Function ReplaceWholeLine(strModuleName, strText As String, strText1 As String) _ As Boolean Dim mdl As Module, lngNumLines As Long Dim lngSLine As Long, lngSCol As Long Dim lngELine As Long, lngECol As Long Dim strTemp As String On Error GoTo Error_ReplaceWholeLine DoCmd.OpenModule strModuleName Set mdl = Modules(strModuleName) If mdl.Find(strText, lngSLine, lngSCol, lngELine, lngECol) Then lngNumLines = Abs(lngELine - lngSLine) + 1 strTemp = LTrim$(mdl.Lines(lngSLine, lngNumLines)) strTemp = RTrim$(strTemp) If strTemp = strText Then mdl.ReplaceLine lngSLine, strText1 Else MsgBox "Line contains text in addition to '" _ & strText & "'." End If Else MsgBox "内容 '" & strText & "' 未找到." End If ReplaceWholeLine = True Exit_ReplaceWholeLine: Exit Function Error_ReplaceWholeLine: MsgBox Err & " :" & Err.Description ReplaceWholeLine = False Resume Exit_ReplaceWholeLine End Function
Function InsertWholeLine(strModuleName, strText As String, strText1 As String) _ As Boolean Dim mdl As Module, lngNumLines As Long Dim lngSLine As Long, lngSCol As Long Dim lngELine As Long, lngECol As Long Dim strTemp As String On Error GoTo Error_InsertWholeLine ' DoCmd.OpenModule strModuleName Set mdl = Modules(strModuleName) If mdl.Find(strText, lngSLine, lngSCol, lngELine, lngECol) Then lngNumLines = Abs(lngELine - lngSLine) + 1 strTemp = LTrim$(mdl.Lines(lngSLine, lngNumLines)) strTemp = RTrim$(strTemp) If strTemp = strText Then mdl.InsertLines lngSLine + 1, strText1 Else MsgBox "Line contains text in addition to '" _ & strText & "'." End If Else MsgBox "内容 '" & strText & "' 未找到." End If InsertWholeLine = True Exit_InsertWholeLine: Exit Function Error_InsertWholeLine: MsgBox Err & " :" & Err.Description InsertWholeLine = False Resume Exit_InsertWholeLine End Function
以上只适用于标准模块和类模块 改成窗体的 大致如下 有兴趣自己在修改下
Private Sub Command0_Click() Call InsertWholeLine(Form_窗体2.Form.Module, "Const conPi = 3.14", "Const conPi = 3.33") End Sub Function InsertWholeLine(frm, strText As String, strText1 As String) _ As Boolean Dim mdl As Module Dim lngNumLines As Long Dim lngSLine As Long, lngSCol As Long Dim lngELine As Long, lngECol As Long Dim strTemp As String Set mdl = frm If mdl.Find(strText, lngSLine, lngSCol, lngELine, lngECol) Then lngNumLines = Abs(lngELine - lngSLine) + 1 strTemp = LTrim$(mdl.Lines(lngSLine, lngNumLines)) strTemp = RTrim$(strTemp) If strTemp = strText Then mdl.InsertLines lngSLine + 1, strText1 Else MsgBox "Line contains text in addition to '" _ & strText & "'." End If Else MsgBox "内容 '" & strText & "' 未找到." End If InsertWholeLine = True Exit_InsertWholeLine: Exit Function Error_InsertWholeLine: MsgBox Err & " :" & Err.Description InsertWholeLine = False Resume Exit_InsertWholeLine End Function Function DeleteWholeLine(frm, strText As String) _ As Boolean Dim mdl As Module, lngNumLines As Long Dim lngSLine As Long, lngSCol As Long Dim lngELine As Long, lngECol As Long Dim strTemp As String On Error GoTo Error_DeleteWholeLine Set mdl = frm If mdl.Find(strText, lngSLine, lngSCol, lngELine, lngECol) Then lngNumLines = Abs(lngELine - lngSLine) + 1 strTemp = LTrim$(mdl.Lines(lngSLine, lngNumLines)) strTemp = RTrim$(strTemp) If strTemp = strText Then mdl.DeleteLines lngSLine, lngNumLines Else MsgBox "Line contains text in addition to '" _ & strText & "'." End If Else MsgBox "内容 '" & strText & "' 未找到." End If DeleteWholeLine = True Exit_DeleteWholeLine: Exit Function Error_DeleteWholeLine: MsgBox Err & " :" & Err.Description DeleteWholeLine = False Resume Exit_DeleteWholeLine End Function Function ReplaceWholeLine(frm, strText As String, strText1 As String) _ As Boolean Dim mdl As Module, lngNumLines As Long Dim lngSLine As Long, lngSCol As Long Dim lngELine As Long, lngECol As Long Dim strTemp As String On Error GoTo Error_ReplaceWholeLine Set mdl = frm If mdl.Find(strText, lngSLine, lngSCol, lngELine, lngECol) Then lngNumLines = Abs(lngELine - lngSLine) + 1 strTemp = LTrim$(mdl.Lines(lngSLine, lngNumLines)) strTemp = RTrim$(strTemp) If strTemp = strText Then mdl.ReplaceLine lngSLine, strText1 Else MsgBox "Line contains text in addition to '" _ & strText & "'." End If Else MsgBox "内容 '" & strText & "' 未找到." End If ReplaceWholeLine = True Exit_ReplaceWholeLine: Exit Function Error_ReplaceWholeLine: MsgBox Err & " :" & Err.Description ReplaceWholeLine = False Resume Exit_ReplaceWholeLine 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)