René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

insert_comment_in_proc [Access macro]

option explicit

sub insert_comment_in_proc()

  dim ac        as access.application
' dim db        as dao.database

  dim vb_editor as vbide.vbe
  dim vb_proj   as vbide.vbProject
  dim vb_comp   as vbide.vbComponents
  dim vb_module as vbide.vbComponent
  dim vb_code   as vbide.codeModule

  dim mdb_name  as string
      mdb_name = "c:\temp\inserted_module.mdb"

  dim module_name as string
      module_name = "ThisModuleWasInserted"

  set ac = new access.application
  ac.openCurrentDatabase(mdb_name)
' set db = ac.currentDB

  set vb_editor = ac.vbe
  set vb_proj   = vb_editor.activeVBProject
  set vb_comp   = vb_proj.vbComponents
  set vb_module = vb_comp(module_name)
  set vb_code = vb_module.codeModule()

' Skip Declaration lines...
  dim current_line as long
      current_line = vb_code.countOfDeclarationLines

  
  do until current_line >= vb_code.countOfLines
     dim proc_name as string
     dim proc_kind as vbide.vbext_procKind

     proc_name = ""

     do until proc_name <> "" or current_line >= vb_code.countOfLines
        proc_name = vb_code.procOfLine(current_line, proc_kind)
        current_line = current_line + 1
     loop

     dim line_start as long
     dim body_start as long
     dim line_count as long

     line_start = vb_code.procStartLine (proc_name, proc_kind)
     body_start = vb_code.procBodyLine  (proc_name, proc_kind)
     line_count = vb_code.procCountLines(proc_name, proc_kind)

     vb_code.insertLines body_start + 1, "' automatically added proc name: " & proc_name & " at line " & line_start & ", count: " & line_count

     current_line = line_start + 1 + line_count + 1

  loop

end sub