473,624 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

searching Access modules

7 New Member
In VBA an Access module has a find method - works perfectly to find a string inside a module. i'm working in A97 (legacy) systems (large ones) and want to write code that searches all modules so that I can check on the possible effects of a change. But the 97 modules collection is open modules only.

Access 97 doesn't have an allmodules collection - 2000+ does - so I can move the app up for this purpose. But now I find that a module in allmodules is an 'access object' and doesn't respond to the module.find method.

Any ideas? thanks

Peter Hall
Jun 9 '07 #1
3 5829
JConsulting
603 Recognized Expert Contributor
In VBA an Access module has a find method - works perfectly to find a string inside a module. i'm working in A97 (legacy) systems (large ones) and want to write code that searches all modules so that I can check on the possible effects of a change. But the 97 modules collection is open modules only.

Access 97 doesn't have an allmodules collection - 2000+ does - so I can move the app up for this purpose. But now I find that a module in allmodules is an 'access object' and doesn't respond to the module.find method.

Any ideas? thanks

Peter Hall
Hi Pete,
I have two...that may or may not work with 97. I apologise if not, as I have no way to test them.

The first is a Joe Kendal module. The second is home grown for a specific purpose, but shows a loop through the Modules Container object.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4. 'Function to Search for a String in a Code Module. It will return True if it is found and
  5. 'False if it is not. It has an optional parameter (NewString) that will allow you to
  6. 'replace the found text with the NewString. If NewString is not included in the call
  7. 'to the function, the function will only find the string not replace it.
  8. '
  9. 'Created by Joe Kendall 02/07/2003
  10. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  11.  
  12. Public Function SearchOrReplace(ByVal ModuleName As String, ByVal StringToFind As String, _
  13.         Optional ByVal NewString, Optional ByVal FindWholeWord = False, _
  14.         Optional ByVal MatchCase = False, Optional ByVal PatternSearch = False) As Boolean
  15.  
  16.     Dim mdl As Module
  17.     Dim lSLine As Long
  18.     Dim lELine As Long
  19.     Dim lSCol As Long
  20.     Dim lECol As Long
  21.     Dim sLine As String
  22.     Dim lLineLen As Long
  23.     Dim lBefore As Long
  24.     Dim lAfter As Long
  25.     Dim sLeft As String
  26.     Dim sRight As String
  27.     Dim sNewLine As String
  28.  
  29.     Set mdl = Modules(ModuleName)
  30.  
  31.     If mdl.Find(StringToFind, lSLine, lSCol, lELine, lECol, FindWholeWord, _
  32.             MatchCase, PatternSearch) = True Then
  33.         If IsMissing(NewString) = False Then
  34.             ' Store text of line containing string.
  35.             sLine = mdl.Lines(lSLine, Abs(lELine - lSLine) + 1)
  36.             ' Determine length of line.
  37.             lLineLen = Len(sLine)
  38.             ' Determine number of characters preceding search text.
  39.             lBefore = lSCol - 1
  40.             ' Determine number of characters following search text.
  41.             lAfter = lLineLen - CInt(lECol - 1)
  42.             ' Store characters to left of search text.
  43.             sLeft = Left$(sLine, lBefore)
  44.             ' Store characters to right of search text.
  45.             sRight = Right$(sLine, lAfter)
  46.             ' Construct string with replacement text.
  47.             sNewLine = sLeft & NewString & sRight
  48.             ' Replace original line.
  49.             mdl.ReplaceLine lSLine, sNewLine
  50.         End If
  51.         SearchOrReplace = True
  52.     Else
  53.         SearchOrReplace = False
  54.     End If
  55.  
  56.     Set mdl = Nothing
  57. End Function
  58.  
  59. Public Sub tryme()
  60.     Dim DB As DAO.DataBase
  61.     Dim ctr As Container
  62.     Dim doc As Document
  63.     Dim amod As Module
  64.  
  65.     On Error Resume Next
  66.  
  67.     Set DB = CurrentDb
  68.     ' Set Container object variable.
  69.     Set ctr = DB.Containers("Modules")
  70.     For Each modu In ctr
  71. '        doc.Properties.Refresh
  72. '        If doc.Name <> "MSys*" And doc.Name <> "~*" Then
  73. '            DoCmd.OpenForm doc.Name, acDesign
  74. '            If Forms(doc.Name).HasModule = True Then
  75. '                DoCmd.OpenModule "Form_" & doc.Name
  76. '                Debug.Print SearchOrReplace("Mod_" & modu.Name, "testing")
  77. '            End If
  78. '            DoCmd.Close acForm, doc.Name
  79. '        End If
  80.     Next
  81.  
  82.     Set ctr = Nothing
  83.     DB.Close
  84.     Set DB = Nothing
  85.     Set doc = Nothing
  86. End Sub
  87.  
  88.  
I'll keep looking around to see if I hve another.
J
Jun 10 '07 #2
peterhall
7 New Member
Hi, thanks for this, the second part of the code trying the container is interesting and I'll try it asap today and tell youi how it goes, thanks again for taking the time to look for this

Peter

Hi Pete,
I have two...that may or may not work with 97. I apologise if not, as I have no way to test them.

The first is a Joe Kendal module. The second is home grown for a specific purpose, but shows a loop through the Modules Container object.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4. 'Function to Search for a String in a Code Module. It will return True if it is found and
  5. 'False if it is not. It has an optional parameter (NewString) that will allow you to
  6. 'replace the found text with the NewString. If NewString is not included in the call
  7. 'to the function, the function will only find the string not replace it.
  8. '
  9. 'Created by Joe Kendall 02/07/2003
  10. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  11.  
  12. Public Function SearchOrReplace(ByVal ModuleName As String, ByVal StringToFind As String, _
  13.         Optional ByVal NewString, Optional ByVal FindWholeWord = False, _
  14.         Optional ByVal MatchCase = False, Optional ByVal PatternSearch = False) As Boolean
  15.  
  16.     Dim mdl As Module
  17.     Dim lSLine As Long
  18.     Dim lELine As Long
  19.     Dim lSCol As Long
  20.     Dim lECol As Long
  21.     Dim sLine As String
  22.     Dim lLineLen As Long
  23.     Dim lBefore As Long
  24.     Dim lAfter As Long
  25.     Dim sLeft As String
  26.     Dim sRight As String
  27.     Dim sNewLine As String
  28.  
  29.     Set mdl = Modules(ModuleName)
  30.  
  31.     If mdl.Find(StringToFind, lSLine, lSCol, lELine, lECol, FindWholeWord, _
  32.             MatchCase, PatternSearch) = True Then
  33.         If IsMissing(NewString) = False Then
  34.             ' Store text of line containing string.
  35.             sLine = mdl.Lines(lSLine, Abs(lELine - lSLine) + 1)
  36.             ' Determine length of line.
  37.             lLineLen = Len(sLine)
  38.             ' Determine number of characters preceding search text.
  39.             lBefore = lSCol - 1
  40.             ' Determine number of characters following search text.
  41.             lAfter = lLineLen - CInt(lECol - 1)
  42.             ' Store characters to left of search text.
  43.             sLeft = Left$(sLine, lBefore)
  44.             ' Store characters to right of search text.
  45.             sRight = Right$(sLine, lAfter)
  46.             ' Construct string with replacement text.
  47.             sNewLine = sLeft & NewString & sRight
  48.             ' Replace original line.
  49.             mdl.ReplaceLine lSLine, sNewLine
  50.         End If
  51.         SearchOrReplace = True
  52.     Else
  53.         SearchOrReplace = False
  54.     End If
  55.  
  56.     Set mdl = Nothing
  57. End Function
  58.  
  59. Public Sub tryme()
  60.     Dim DB As DAO.DataBase
  61.     Dim ctr As Container
  62.     Dim doc As Document
  63.     Dim amod As Module
  64.  
  65.     On Error Resume Next
  66.  
  67.     Set DB = CurrentDb
  68.     ' Set Container object variable.
  69.     Set ctr = DB.Containers("Modules")
  70.     For Each modu In ctr
  71. '        doc.Properties.Refresh
  72. '        If doc.Name <> "MSys*" And doc.Name <> "~*" Then
  73. '            DoCmd.OpenForm doc.Name, acDesign
  74. '            If Forms(doc.Name).HasModule = True Then
  75. '                DoCmd.OpenModule "Form_" & doc.Name
  76. '                Debug.Print SearchOrReplace("Mod_" & modu.Name, "testing")
  77. '            End If
  78. '            DoCmd.Close acForm, doc.Name
  79. '        End If
  80.     Next
  81.  
  82.     Set ctr = Nothing
  83.     DB.Close
  84.     Set DB = Nothing
  85.     Set doc = Nothing
  86. End Sub
  87.  
  88.  
I'll keep looking around to see if I hve another.
J
Jun 10 '07 #3
peterhall
7 New Member
Hi J, thanks for this, the second part of the code trying the container is interesting and I'll try it asap today and tell youi how it goes, thanks again for taking the time to look for this

Peter
Jun 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2703
by: rufus | last post by:
Hi, On the project I am working on we need to encapsulate all data and business logic in an activex dll. My question is: How do I do this? How can I access the form objects ie text boxes, buttons with a dll? Thanks.
55
3529
by: AnandaSim | last post by:
I just had a google through this NG but have not seen mention of Erik Rucker's blog entry and the new Jet: http://blogs.msdn.com/access/archive/2005/10/05/477549.aspx mentioned by Mike Gunderloy http://www.larkware.com/dg4/TheDailyGrind726.html Aside from the Sharepoint feature extension, amazing news.
5
1952
by: jqpdev | last post by:
Hello all... I'm coming from a Borland Delphi background. Delphi has a specific component called a Data Module. In the designer the Data Module behaves like a windows form. A developer can drop non-visual (controls) on the data module surface and wire them up and create procedures, functions, event procedures. In the source file (code behind file) the Data Module is a class, and the dropped components are public properties. The...
13
2348
by: Robin Haswell | last post by:
Hey people I'm an experience PHP programmer who's been writing python for a couple of weeks now. I'm writing quite a large application which I've decided to break down in to lots of modules (replacement for PHP's include() statement). My problem is, in PHP if you open a database connection it's always in scope for the duration of the script. Even if you use an abstraction layer ($db = DB::connect(...)) you can `global $db` and bring...
1
1559
by: nandar | last post by:
Hi All, I am involved in migratinig one of the MS Access Project to ASP.Net and SQL Server 2000. My question here is that how Modules and Class Modules can be taken care in ASP.Net. To some extend I know the answer but I want to know whether that is the right way or any other solution is available. My understanding is, 1) MS Access Modules will be placed in the App_code directory (wrt .Net 2.0) and set the Methods and the variables to...
0
1205
by: nandar | last post by:
Hi All, I am involved in migratinig one of the MS Access Project to ASP.Net and SQL Server 2000. My question here is that how Modules and Class Modules (MS Access) can be taken care in ASP.Net. To some extend I know the answer (I beleive) but I want to know whether that is the right way or any other solution is available. My understanding is, 1) MS Access Modules will be placed in the App_code directory (wrt .Net 2.0) and set the Methods...
0
11583
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access Security, but I'll start with something short and simple This code was written in Access 2003 but should be valid in Access 2000 By default, when you start a new module, either in a form or report, or a global module, Access does not declare Option...
3
2394
by: Roy Tong | last post by:
I maintain a shared database on Access 97. I've just tried converting a test copy of the database to 2003 and it appeared to work OK. That is I got no error messages. However then I look at my modules, only 2 out of 9 have copied across. Do I need to do something special to recompile modules and take them across to the new version? I thought the conversion process would just handle it. Well it seems to for 2 of the 9 and I got no...
4
3805
by: howard.canaway | last post by:
I have always wondered about the specification page in the Access Help files. It reads Microsoft Access database (.mdb) file size 2 gigabytes. However, because your database can include linked tables in other files, its total size is limited only by available storage capacity. Number of objects in a database 32,768 Modules (including forms and reports with the HasModule property set to True) 1,000 Number of characters in an object name...
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.