Problem Editing Modules

G

Guest

Hi, all...

Having problem setting a reference to an object module so that I can
search/replace using VB Code. Here's a snippet:

Option Explicit
....
Dim mdl As Module 'Referenced by other Subs
....
Sub EditModules
....
Dim NamesArray(99, 1) As String
Dim b As Integer
....
'Open the object to be edited and set its reference.
Select Case NamesArray(b, 1)
Case "Module": 'This one works
DoCmd.OpenModule NamesArray(b, 0)
Set mdl = Modules(NamesArray(b, 0))
Case "Form": 'This one does not work
DoCmd.OpenForm NamesArray(b, 0), acDesign
Set mdl = Modules("Form_" & NamesArray(b, 0))
Case "Report": 'This one does not work
DoCmd.OpenReport NamesArray(b, 0), acDesign
Set mdl = Modules("Report_" & NamesArray(b, 0))
End Select
....
End Sub

When I run the code, I get a 7961 error, "Microsoft Access can't find the
module 'Form_QuoteDetail' referred to in a macro expression or Visual Basic
code." on the "set" line for Forms and Reports.

The module name is correct as shown in Class Objects, and the form is open
in design mode. The error does not occur on Standard modules.

Gunny provided this answer to a question earlier in the month, but I've
checked all of this and it doesn't help:
DoCmd.OpenModule "Form_" & strFormName

You have the correct syntax. Ensure that the form is open before this code
executes, it has a module, and that the name of the form doesn't contain any
illegal characters and isn't a Reserved word. And ensure that Option
Explicit is written in the module's Declarations section, just in case you
have a typo on the form's variable name.

Any idea how to get the reference to work?

Thanks,
Bruce
 
G

Guest

Never mind...answered my own question. I was failing to open the module
after I opened the form/report.

Thanks,
Bruce

BruceS said:
Hi, all...

Having problem setting a reference to an object module so that I can
search/replace using VB Code. Here's a snippet:

Option Explicit
...
Dim mdl As Module 'Referenced by other Subs
...
Sub EditModules
...
Dim NamesArray(99, 1) As String
Dim b As Integer
...
'Open the object to be edited and set its reference.
Select Case NamesArray(b, 1)
Case "Module": 'This one works
DoCmd.OpenModule NamesArray(b, 0)
Set mdl = Modules(NamesArray(b, 0))
Case "Form": 'This one does not work
DoCmd.OpenForm NamesArray(b, 0), acDesign

*** Added this line.
DoCmd.OpenModule("Form_" & NamesArray(b, 0))
Set mdl = Modules("Form_" & NamesArray(b, 0))
Case "Report": 'This one does not work
DoCmd.OpenReport NamesArray(b, 0), acDesign

*** Added this line.
DoCmd.OpenModule("Report_" & NamesArray(b, 0))
 

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