Replace (Ctrl + H) with Newline character in VBE (1 Viewer)

Babycat

Member
Local time
Tomorrow, 04:25
Joined
Mar 31, 2020
Messages
275
Hi all

I have many forms and modules in VBA code. My code usually has a line in comment mode like
Code:
'On Error GoTo ErrorHandler
thus, this error handler is temporary disabled during the code development.

Now, I want to replace above line by using a compiler switch such as
Code:
#If DEVMODE Then
#Else
    On Error GoTo ErrorHandler
#End If

Is there any way to do it (Ctrl+H) in VBA Editor for multiple modules?

I only can think about manually copy one by one to word or txt file, then use Ctrl+H in these editors. But, this is kind of time consuming...
 

Josef P.

Well-known member
Local time
Today, 23:25
Joined
Feb 2, 2023
Messages
826
Probably there will be add-ins that allow multi-line substitution.

If not:
a)
1. export modules with Application.SaveAsText
2. replace with Notepad+ & co.
3. import with Application.LoadFromText

b)
Modify code in modules with VBA. (vbComponents, Codemodule, ...)


But:
Why do you need that at all?
Why don't you switch to error trapping "Break on all errors" in DEV mode?
Code:
Application.SetOption "Error Trapping", 0
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:25
Joined
Feb 19, 2002
Messages
43,283
I don't understand why you would disable error trapping during development.
 

ebs17

Well-known member
Local time
Today, 23:25
Joined
Feb 7, 2020
Messages
1,946
It would be more efficient to set the VBE editor to interrupt with every error.
This promotes programming that avoids errors.
 

Babycat

Member
Local time
Tomorrow, 04:25
Joined
Mar 31, 2020
Messages
275
Yes
I don't understand why you would disable error trapping during development.
Yes, like ebs17's comment, I want Access stop at every error code so that I can jump into it and investigate in detail.
My Error handler mostly consists of "Resume Next", thus I disable error trapping to try catching all unforeseeable errors.
 
Last edited:

Babycat

Member
Local time
Tomorrow, 04:25
Joined
Mar 31, 2020
Messages
275
Probably there will be add-ins that allow multi-line substitution.

If not:
a)
1. export modules with Application.SaveAsText
2. replace with Notepad+ & co.
3. import with Application.LoadFromText

b)
Modify code in modules with VBA. (vbComponents, Codemodule, ...)


But:
Why do you need that at all?
Why don't you switch to error trapping "Break on all errors" in DEV mode?
Code:
Application.SetOption "Error Trapping", 0
Appreciated so much for your suggestions,
I just simply dont know about Application.SetOption "Error Trapping". It seems to be what I need. Let me try it out.
 

Josef P.

Well-known member
Local time
Today, 23:25
Joined
Feb 2, 2023
Messages
826
Application.SetOption "Error Trapping", {0|1|2} set the error trapping option in "Options" window:
ErrorTrapping.png
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:25
Joined
Feb 19, 2002
Messages
43,283
Break on unhandled errors is the most useful method. Then you don't need to change the setting at run time. Once you've handled an error, you don't need to worry about it any more. Use a case statement in your error handler and let all unhandled errors fall through to the Else part. As you encounter errors, you can just add them to the Select clause. I display both err.Number and err.description in the Else to make it easy on myself to modify the Select to catch specific errors.
 

Josef P.

Well-known member
Local time
Today, 23:25
Joined
Feb 2, 2023
Messages
826
Break on unhandled errors is the most useful method. Then you don't need to change the setting at run time.
You have to be careful there. This option applies system-wide. If a user sets this option to "Break on oll errors" in Excel, for example, this option is then also set for Access.
It is best to use an accde for the productive environment, then "Break on unhandles errors" always applies.

I usually use "Break on oll errors" on my developer PC, then I don't have to search for the line with the error. :)
 
Last edited:

SHANEMAC51

Active member
Local time
Tomorrow, 00:25
Joined
Jan 28, 2022
Messages
310
I have many forms and modules in VBA code. My code usually has a line in comment mode like
Code:
Sub mod_edit_debug()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' sometimes I use something like this code
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim obj As AccessObject
Dim mdl As Module
Dim sname As String
Dim j1 As Long, j1k As Long
Dim s1 As String, s1a As String

For Each obj In Access.CurrentProject.AllModules
    sname = obj.Name
    DoCmd.OpenModule sname
    Set mdl = Modules(sname)
    j1k = mdl.CountOfLines
    Debug.Print sname, j1k
    j1 = 0
    Do While j1 < j1k
    ''''''''''''''''''''''''''''''''
        j1 = j1 + 1
        s1 = Trim(mdl.Lines(j1, 1))
        s1a = s1
        ''''''''''''''''''''''''''''
        If s1 Like "debug.*" Then
        s1a = "'" & s1
        End If
        ''''''''''''''''''''''''''''
        If s1 Like "'debug.*" Then
        s1a = Mid(s1, 2)
        End If
        ''''''''''''''''''''''''''''
        If s1 <> s1a Then
        mdl.ReplaceLine j1, s1a
        End If
        ''''''''''''''''''''''''''''
    Loop
    DoCmd.Close acModule, sname, acSaveYes
Next obj
End Sub
 

SHANEMAC51

Active member
Local time
Tomorrow, 00:25
Joined
Jan 28, 2022
Messages
310
it can be configured to replace the word you are looking for or a module for processing
 

Users who are viewing this thread

Top Bottom