Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Developers    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Global Edit VBA code
Sami Shamma 
             
2 years ago
Friends,

Is there a way to edit the VBA code from outside the VBA editor? I know it sound silly, but this is what I like to do:

I would like to insert a comment line on top of every code block with a copyright statement.

Thanks
Thomas Gonder  @Reply  
      
2 years ago
I think so. You might want to check out Mike Wolf's site. Search for "doc tests".
There's code in there that somehow plays with the VBA source. It's quite complicated and I don't understand all he was doing, but I managed to hack it to do what I wanted.

It's probably faster to just paste it in with the editor.
I place a copyright notice at the top of each module, and then a few hidden ones in case someone tries to decompile the code from an .accde. I've let the vendor that decompiles VBA code know that I have that message in there, and if they see it, they don't have permission to share the code.
Thomas Gonder  @Reply  
      
2 years ago
To continue on, placing a comment in source probably gets discarded when VBA compiles down to p-code.
So, your best protection is to place your copyright message in a reuseable const and that will force the p-code to contain the copyright message, and show if decompiled.
Sami Shamma OP  @Reply  
             
2 years ago
Thank Thomas
Adam Schwanz  @Reply  
           
2 years ago
This is one thing that I've had "pretty good" luck with chatgpt for. Just copy/paste the entire page of code in, ask it to insert a comment line (or to lesser success, have it try to comment what is going on in the code), then copy/paste the result back in. There has been a couple times it's screwed up my code though with its "improvements" so maybe not worth the risk :P, or at least keep an eye out.
Richard Rost  @Reply  
          
2 years ago
If you have Option Explicit or Option Compare Database at the top of every module as you should, then you can do a global replace in the entire database project and put your copyright notice above that by simply replacing Option Explicit with Option Explicit and your copyright notice.
Sami Shamma OP  @Reply  
             
2 years ago
I knew Richard will come up with a simple elegant solution.

Thanks.
Sami Shamma OP  @Reply  
             
2 years ago
How do I insert CR,NL characters in the replace box?

I am replacing:

Option Compare Database
with
'Shamma Consultancy (c)
Option Compare Database

Char(10) Char(13) did not work
Thomas Gonder  @Reply  
      
2 years ago

Thomas Gonder  @Reply  
      
2 years ago
Just a suggestion Sami, Write something like I did above. Then search for the Option Compare, and paste in the appropriate part before the Option.
Take it to the next level by using a variable (I made a mistake above, I changed to using a variable from a const) of the same message in the two wSql = statements (for the reason given above). You can cut and paste that part too, to selected VBA code (or everywhere if you wish) using your own string variable. How many modules do you have that a little F3 -> ctrl-v won't work (probably 20% of my coding time is spent with just those two keystrokes)?!!!

Notice all the useful information that is there in the module header. Doesn't every module deserve that (or better)?
Sami Shamma OP  @Reply  
             
2 years ago
Thomas,

That went right over my head. Your suggestion is exactly what I tried to do. I just could not separate my line from the Option Compare line.
Sami Shamma OP  @Reply  
             
2 years ago
Adam

My code is well documented, I just want to add one comment on top with my copyright message.
Richard Rost  @Reply  
          
2 years ago
OK, you're not crazy... the standard find/replace dialog doesn't allow multiple lines. Gimme a sec...
Richard Rost  @Reply  
          
2 years ago
OK. I have a solution for you. Hold tight.
Richard Rost  @Reply  
          
2 years ago
Here you go... it's in the Code Vault. Find Replace VBA Code

Video will follow. Good question, BTW.
Sami Shamma OP  @Reply  
             
2 years ago
You are the best!!!!!
Sami Shamma OP  @Reply  
             
2 years ago
Now I have a certificate from Richard that I am not crazy.
Did you hear that Mom?
Alex Hedley  @Reply  
           
2 years ago
You could do it with {vcs}
The code is exported to text files and you can manipulate everything much easier.
Sami Shamma OP  @Reply  
             
2 years ago
Alex, please tell me more.
Alex Hedley  @Reply  
           
2 years ago
Well hopefully you are keeping a backup of all your dbs with VCS / GitHub
You have the files on disc, which can then be modified and rebuilt into a db
Richard Rost  @Reply  
          
2 years ago
Oh boy... Alex caught another fish on his VCS hook...
Thomas Gonder  @Reply  
      
2 years ago
With a good and simple video explaining how to use VCS, I would be prone to consider its advantages.
The problem is, even after watching a video, I have no idea how to USE it.
The other half of that to this thread, in what new language am I going to modify the VBA text files?
Richard, provided a cool way in VBA within Access, and I like it, but now to have to export, modify and import, and hope it all works? I don't know, going to have to do a lot to convince me.
Thomas Gonder  @Reply  
      
2 years ago
The above comment being said, I was partners, many moons ago, with a good truck driver turned super programmer. He wrote a system to merge the code from different programmers, saved on 1/2" tape that they kept as they moved from client to client and made mods. There were five of us. I wouldn't want to write that kind of system of Ted's.

Should I ever decide to herd cats again, which will probably happen sooner than I like, yes VCS may be a great tool.
Now, someone please explain it so I can complicate my life even more!
Alex Hedley  @Reply  
           
2 years ago
I'd welcome suggestions to improve the video, what was missing?

Firstly I'd suggest downloading the AddIn and trying it out, pick a db and export it to see what it produces.

It's your choice of what language to use, which do you feel most comfortable in? You could even just do it manually with VSCode, as it's Find/Replace is far superior to that of the VBE.
Thomas Gonder  @Reply  
      
2 years ago
@ Alex, I'll watch the video again, and comment from the perspective of someone that has no experience with it, and then wants to add the AddIn, configure it, export a sample db and then import it. Step by clear step. Then we can move on to the multi-programmer environment and other tools in VCS. Sound good? of course, I'll need some way to msg with you as not to klug up 599CD.com
Alex Hedley  @Reply  
           
2 years ago
You're welcome to comment on the video page itself :)
Richard Rost  @Reply  
          
2 years ago
You're not klugging up anything. That's what these forums are for.
Thomas Gonder  @Reply  
      
2 years ago
I made a quick video, doing exactly what Sami wanted using only the F3 and ctrl+V keys.
I'm curious if there is something I'm not understanding.
How can I get the .mp4 file here for showing what I meant in my post?
Alex Hedley  @Reply  
           
2 years ago
Videos aren't supported
You'd have to upload to YouTube or equivalent and then post the link.
Sami Shamma OP  @Reply  
             
2 years ago
Richard,

Not that I had any doubts, but your code worked perfectly.
Thomas Gonder  @Reply  
      
2 years ago
@ Alex, I don't think links are allowed here either (or maybe they are for developers, I'm not sure). So, how?
I'll place the link to my Google Drive for the video and those that want to comment on what I may be missing in Sami's question:
https://drive.google.com/file/d/1aElRjdX7kdZr_uBamHD5VYhML-612YWK/view
Adam Schwanz  @Reply  
           
2 years ago
Thomas your video works fine if your only doing a few, if you wanted to put this across a lot it becomes more annoying (still doable with your method, but not instant). I think in Sami's case he wanted to add a line above every object (forms,reports,etc) which could potentially be 50+. Just doing it one time would be a large time save potentially.
Richard Rost  @Reply  
          
2 years ago
The "no links" rule is more of a guideline. If it's someone (like you) who participates in the Forums often and wants to share a DB or a video to further discussion like this, that's fine. If is a newb who's like "come see my website" then no. Axed. The moderators are trusted to use their judgement.

And links like YouTube videos or Google Drive files are generally OK because you can't change them. I had a guy once who posted a link to an image on his website that was fine when I first checked it (a diagram of his database), but he subsequently changed it to something... inappropriate. So I don't allow that anymore.
Thomas Gonder  @Reply  
      
2 years ago
@ Adam, I'll bet that I could F3 > ctrl+V 50xs in less time that it took Richard to go to Chat GPT, pose the question, copy it, and test the code. I doubt that Sami has 50 modules, and he only mentioned VBA code in the first post. I'm not sure where he would want to place it in other objects.

I put a copyright notice in all "live" forms and reports. That way the client can legally protect their organization data. For example, say an employee sells a copy of sensitive information to a competitor, the lawyers have the evidence of criminal activity to work with. The laws are there for more than copying music/video files.

@ Richard, I'll try to give the link some permanence, but I have no idea what will happen if I later reorganize the folders in Drive.
Thomas Gonder  @Reply  
      
2 years ago

Richard Rost  @Reply  
          
2 years ago
Let's race. 😁

I see something that can be automated with a little programing and it's "challenge accepted..."
Thomas Gonder  @Reply  
      
2 years ago
@ Richard, ha ha, don't get me wrong, it's a great little ditty and great to know that code can modify code. I thought that there was something "protected" about VBA code, hence Mike Wolfe's really complicated routine (but it was to run the code from other code). And there's MZ-Tools and its magical mystery.  I'll be in the code vault and giving it a good look next time I need to do some "heavy lifting" mods in thousands of lines of code.
John Davy  @Reply  
         
2 years ago
Hi Sami
I don't use third party tools often but I do use a great one by Philipp Stiefel. This will find and replace just about anything in Access. I use it all the time and it has save me thousands of dollars. AccDevTools. It will search and replace in tables, queries, Forms, reports, Modules and VBA.

HTH
John
Sami Shamma OP  @Reply  
             
2 years ago
Thank you John
I will definitely give it a try.
Thomas Gonder  @Reply  
      
2 years ago
@ John, That's a good looking tool based on the website, but when I downloaded the .msi, and double clicked on it, like the instructions say, Notepad popped up and various apps, like Access froze and now my computer is a mess.
Thomas Gonder  @Reply  
      
2 years ago
@ John, Because I'm a glutton for punishment, I tried the Access Dev Tools .msi for Find and Replace on another laptop, this one with Windows 10 and Office 365 in Spanish. The .msi ran and seemed to install, but when I tried to run Access, Access barfed up the below message. So, that's two laptops with different Windows and Access versions that don't like the utility.
Thomas Gonder  @Reply  
      
2 years ago

Thomas Gonder  @Reply  
      
2 years ago
Cont. To be fair, I'll report some good news. It's Sunday morning, and Philipp of AccessDevTools Support emailed me back with a solution. According to him, my computer was messed up with the msi installer. His solution worked, and I installed the tool.

The really good news is that I did a search for a code I use for forms. I had changed it yesterday, an hours long painstaking process. The Find and Replace tool found 29 instances of the code in all kinds of interesting places. Most of which I overlooked, and a few more that were left-over errors from when I copied the form to create a new one. Wow, as a debugging tool.

Based on the recent experience, I give it a big thumbs up (provided there are no more problems).
I see that Philipp has a new email msg for me about the other computer's problem. Got to go check it out. Good response time from their support.
Sami Shamma OP  @Reply  
             
2 years ago
Ok. I think I will try it now.
Richard Rost  @Reply  
          
2 years ago
Always good when support people get back to you quickly. That's why I prefer doing business with small companies / entrepreneurs. :)
Kevin Yip  @Reply  
     
2 years ago
Microsoft should just remake the whole VBA editor app by adding a whole host of important features like the one mentioned here, also regular expression search, better intellisense, better theme coloring, etc.  These aren't small quality-of-life features either.  These are essential nowadays in any coding environment.  Maybe there weren't essential 30+ years ago when Access first came out, but they are today.
Richard Rost  @Reply  
          
2 years ago
Hear hear!
Sami Shamma OP  @Reply  
             
2 years ago
I purchased the tool suggested by John.
Installed with no problems, activated with no issues.

This is a game changer.  Thank you, John.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developers.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/7/2026 10:44:11 PM. PLT: 1s