Using code to edit modules

K

Ken

I have a large database with a number of modules. Most of my functions have
some type of error messages that get outputted when I check the data.

I have a call to add the error to a table. I would like each call to have a
unique id within each function.

I have been trying to find code that could find the call in a function and
then edit the id.

My call has the format of :

Call AddErrorToTable KeyID, "<FunctionName>_01", <table>, <field>, <input
form>, <Error String>)

Is there a way to have VB code go through all the modules look for the call
and than update the function name and error number?

Thanks.
 
M

Marshall Barton

Ken said:
I have a large database with a number of modules. Most of my functions have
some type of error messages that get outputted when I check the data.

I have a call to add the error to a table. I would like each call to have a
unique id within each function.

I have been trying to find code that could find the call in a function and
then edit the id.

My call has the format of :

Call AddErrorToTable KeyID, "<FunctionName>_01", <table>, <field>, <input
form>, <Error String>)

Is there a way to have VB code go through all the modules look for the call
and than update the function name and error number?

You can use the properties and methods of the Module object
to find and change code. To check all standard and Class
modules, loop through the Modules collection.

For forms and reports, loop through the
CurrentProject.AllForms or AllReports collections. Open the
form/report in design view, check the form/report's
HasModule property and if Yes, use the form/report's Module
property to get to its module object.
 
K

Ken

I found an example that uses the find and replace for a module object, but
it only seems to be doing one find in each module.

mdl.Find(StringToFind, StartLine, StartCol, EndLine, EndCol, FindWholeWord,
MatchCase, PatternSearch)

Do I set the Startline to be the last found + 1?

Also, when I issue the mdl.replace function I keep getting a error message
that I can not set a break point?
 
G

Guest

Just to note, I use Erl

If you give unique line numbers to your lines, you get a unique
index in your error table. Like a primary key for code lines.

You can't go completely unique for very large projects, because
MS reduced the range of valid lines numbers, but it's close enough.
..
(david)
 
M

Marshall Barton

Ken said:
I found an example that uses the find and replace for a module object, but
it only seems to be doing one find in each module.

mdl.Find(StringToFind, StartLine, StartCol, EndLine, EndCol, FindWholeWord,
MatchCase, PatternSearch)

You need to use Find more like:

lngStart = 0
Do While True
lngStart = lngStart+1
resp = mdl.Find(StringToFind, lngStart, . . .)
If Not resp then Exit Do
. . .
Loop

Do I set the Startline to be the last found + 1?

yes, see above.

Also, when I issue the mdl.replace function I keep getting a error message
that I can not set a break point?

There is no Replace method for module objects. Maybe you
want ReplaceLine
 
K

Ken

Marshall,

Thanks for the information. I tried that late last night and found that the
find would then miss the next line. I used the find to find the first
occrance and then read each line in the module one at a time.

Thanks again.
 
M

Marshall Barton

I don't understand the part about "miss the next line", but
if you have something that works, it probably doesn't
matter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top