Hi Everyone
This post follows fromt the post "do I need to set objects to nothing".
Here is a function that I used to add a line of code to all procedures.
It is pretty rought, but it seemed to work in most instances....
Public Function AddRstClose(Mod uleName As String, SearchFor As String, PutAt
As String, PutBefore1 As String, PutBefore2 As String, ADDs As String) As
Boolean
''on error GoTo er
'searches for SSa in a module and if it finds ...
'then makes sure that it does not occur past a certain colum (character)
NOTE: set to -1 to ignore this test
'then checks if SSb occurs on the same line and ...
'then replaces SSa or SSb with a new phrase
Dim MDL As Module
Dim i As Byte
Dim S As String
Dim eline As Long
Dim ecol As Long
Dim sline As Long
Dim scol As Long
Dim P(100, 3) As Long
Dim T As Byte
' Open module.
DoCmd.OpenModul e ModuleName
' Return reference to Module object.
Set MDL = Modules(ModuleN ame)
For i = 1 To 100
sline = sline + 1
If MDL.type = acClassModule Then GoTo i_looper
eline = Empty
ecol = Empty
'find the place where rst is declared
S = SearchFor: T = 0: GoSub pp
S = PutAt: T = 1: GoSub pp
S = PutBefore1: T = 2: GoSub pp
S = PutBefore2: T = 3: GoSub pp
If (P(i, 2) > P(i, 3) And P(i, 3) > 0) Or P(i, 2) = 0 Then
P(i, 2) = P(i, 3)
End If
P(i, 3) = P(i, 2)
sline = P(i, 2)
If P(i, 0) > 0 And P(i, 0) < P(i, 1) And P(i, 1) < P(i, 2) Then
Debug.Print "writing line on " & P(i, 1) + 1
MDL.InsertLines P(i, 1) + 1, ADDs
Else
Debug.Print "not writing line on " & P(i, 1) + 1
End If
i_looper:
If MDL.CountOfLine s < sline + 3 Then i = 101
Next i
xt: On Error Resume Next
DoCmd.close acModule, ModuleName, acSaveYes
Exit Function
er:
MsgBox ERR.number & ": " & ERR.Description
Resume xt
pp:
If MDL.find(S, sline, scol, eline, ecol) Then ' Search for ing.
P(i, T) = eline
If eline > 0 And T < 2 Then
sline = eline
Else
If T = 2 Then
'sline = P(i, 1)
End If
End If
Else
If T = 0 Then
GoTo xt
Else
P(i, T) = 0
End If
End If
eline = Empty
ecol = Empty
scol = Empty
Debug.Print S & ":" & sline,
Return
End Function
I used the following line to call it:
call AddRstClose(Mdl N, "Dim Rst as recordset", "xt:", "end function", "end
sub", " If Not (RST Is Nothing) Then RST.close: Set RST = Nothing")
where xt: is where I exit my functions.....
Cheers
- Nicolaas
This post follows fromt the post "do I need to set objects to nothing".
Here is a function that I used to add a line of code to all procedures.
It is pretty rought, but it seemed to work in most instances....
Public Function AddRstClose(Mod uleName As String, SearchFor As String, PutAt
As String, PutBefore1 As String, PutBefore2 As String, ADDs As String) As
Boolean
''on error GoTo er
'searches for SSa in a module and if it finds ...
'then makes sure that it does not occur past a certain colum (character)
NOTE: set to -1 to ignore this test
'then checks if SSb occurs on the same line and ...
'then replaces SSa or SSb with a new phrase
Dim MDL As Module
Dim i As Byte
Dim S As String
Dim eline As Long
Dim ecol As Long
Dim sline As Long
Dim scol As Long
Dim P(100, 3) As Long
Dim T As Byte
' Open module.
DoCmd.OpenModul e ModuleName
' Return reference to Module object.
Set MDL = Modules(ModuleN ame)
For i = 1 To 100
sline = sline + 1
If MDL.type = acClassModule Then GoTo i_looper
eline = Empty
ecol = Empty
'find the place where rst is declared
S = SearchFor: T = 0: GoSub pp
S = PutAt: T = 1: GoSub pp
S = PutBefore1: T = 2: GoSub pp
S = PutBefore2: T = 3: GoSub pp
If (P(i, 2) > P(i, 3) And P(i, 3) > 0) Or P(i, 2) = 0 Then
P(i, 2) = P(i, 3)
End If
P(i, 3) = P(i, 2)
sline = P(i, 2)
If P(i, 0) > 0 And P(i, 0) < P(i, 1) And P(i, 1) < P(i, 2) Then
Debug.Print "writing line on " & P(i, 1) + 1
MDL.InsertLines P(i, 1) + 1, ADDs
Else
Debug.Print "not writing line on " & P(i, 1) + 1
End If
i_looper:
If MDL.CountOfLine s < sline + 3 Then i = 101
Next i
xt: On Error Resume Next
DoCmd.close acModule, ModuleName, acSaveYes
Exit Function
er:
MsgBox ERR.number & ": " & ERR.Description
Resume xt
pp:
If MDL.find(S, sline, scol, eline, ecol) Then ' Search for ing.
P(i, T) = eline
If eline > 0 And T < 2 Then
sline = eline
Else
If T = 2 Then
'sline = P(i, 1)
End If
End If
Else
If T = 0 Then
GoTo xt
Else
P(i, T) = 0
End If
End If
eline = Empty
ecol = Empty
scol = Empty
Debug.Print S & ":" & sline,
Return
End Function
I used the following line to call it:
call AddRstClose(Mdl N, "Dim Rst as recordset", "xt:", "end function", "end
sub", " If Not (RST Is Nothing) Then RST.close: Set RST = Nothing")
where xt: is where I exit my functions.....
Cheers
- Nicolaas