Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't enter brak mode at this time

Status
Not open for further replies.

rewdee

Programmer
Aug 17, 2001
295
US
I'm trying to strip the comments from a module and then iterate through the module finding queries, macros,etc. already in the db.

I am using a modified version found in the Access Developer's Handbook (adh). The code is as below:
***********************************************
Dim cLine As Long

If ctrType = acModule Then
If aDoc.Name <> &quot;Module1&quot; Then
DoCmd.OpenModule aDoc.Name
With Modules(aDoc.Name)
On Error Resume Next
For cLine = .CountOfLines - 1 To 0 Step -1
If InStr(Trim(.Lines(cLine, 1)), &quot;'&quot;) = 1 Then
'.DeleteLines cLine, 1
Modules(aDoc.Name).DeleteLines cLine, 1
End If
Next
End With
DoCmd.Close acModule, aDoc.Name, acSaveNo
End If
End If
********************************************************
I keep getting getting a message &quot;Can't enter break mode at this time&quot; at the line:

Modules(aDoc.Name).DeleteLines cLine,1

I don't know why I am getting this messge and causes the process to stop working. What's funny is that it does not appear to be an error because my On Error Resume Next does not seem to help.

If anyone has any ideas or can help me, I sure would appreciate it.

Thanks,
Rewdee

 
Hi!

Does this code reside in Module1, or is it in a public procedure called by Module1? Usually you get this message when you try to do something to an object that requires it to be in design mode and it is already open in another mode(such as a module which is already running, or a form that is running code).

hth
Jeff Bridgham
 
Rats, I wish that was the answer but the code resides in Module1 and I am testing it from within Module1. and I've tried both declaring the procedure Private and Public and I still get the same message.

Thanks,
Rewdee
 
Hi!

I think you misread my post, or I miswrote my post. Having the code in module1 and running it from there will give you this error message. Having this code in a different module, which is then called by a procedure in module1 will also give you this error message. What Access is trying to say is that module1 is running and to delete a line from module1 it must be in design view. A module cannot be in design view and running at the same time, therefore you get the message which says Access can't go into break mode at this time.

hth
Jeff Bridgham
 
Sorry Jeff about the misread but no I'm not trying to delete from Module1. I know this is a lowtech way but I am preventing this happening by writing the line of code:

If aDoc.Name <> &quot;Module1&quot; Then

So that is not the problem (at least as I see it).

thanks Jeff, keep on trying though, I know you will think of something I haven't.

Rewdee
 
Hi!

Well, I'll try. Could you post the rest of the code so I can see where aDoc and ctrType are coming from and what the procedure does with the variables prior to this section of the code.

Jeff Bridgham
 
Thanks Jeff (and all) for the help. Here's the code:

____________________________________
Sub DocMod()
ImportModules
DoStripComments
'get properties, procedures,etc
End Sub
_____________________________________
Private Sub ImportIt(ObjectType As Long, ObjectName As String,sPath as String)
On Error Resume Next
DoCmd.TransferDatabase acImport, &quot;Microsoft Access&quot;, sPath, ObjectType, ObjectName, ObjectName
End Sub
_______________________________________

Private Sub ImportModules(sPath as String)
On Error Resume Next
Dim dbEs As DATABASE
Dim ctr As Container
Dim doc As Document

Set dbEs = OpenDatabase(sPath)
Set ctr = dbEs.Containers(&quot;Modules&quot;)
ctr.Documents.Refresh

For Each doc In ctr.Documents
ImportIt acModule, doc.Name
Next doc

Set dbEs = Nothing
End Sub
_________________________________________________________
Dim db As DATABASE
Dim ctr As Container
Dim doc As Document

Set db = CurrentDb
Set ctr = db.Containers(&quot;Modules&quot;)
ctr.Documents.Refresh

Set ctr = db.Containers(&quot;Modules&quot;)
For Each doc In ctr.Documents
StripComments acModule, doc
Next doc

Set db = Nothing
__________________________________________
Public Sub StripComments(ctrType As Long, aDoc As Document)
Dim cLine As Long

If ctrType = acModule Then
If aDoc.Name <> &quot;Module1&quot; Then
DoCmd.OpenModule aDoc.Name
With Modules(aDoc.Name)
'On Error Resume Next

For cLine = .CountOfLines - 1 To 1 Step -1
If InStr(Trim(.Lines(cLine, 1)), &quot;'&quot;) = 1 Then
'.DeleteLines cLine, 1
Modules(aDoc.Name).DeleteLines cLine, 1
End If
Next
End With
DoCmd.Close acModule, aDoc.Name, acSaveNo
End If
End If

End Sub
__________________________________________________________

Originally I had a call to StripComments right in the ImportModules right after the line: ImportIt acModule, doc.Name but I got the same so error/notice so I had to break it apart.

Any Ideas?
Rewdee

 
Hi!

The only idea I have to leave out the line which says:

DoCmd.OpenModule aDoc.Name

See if that helps.

Jeff Bridgham
 
Thanks Jeff but &quot;NoCanDo&quot;. Access will not let you operate on a closed object most of the time and specifically a Module has to be open to get at its properties and the VBA code.

Rewdee
 
Hi!

Okay, you're right! :)

Try this:

Dim mdl As Module

Set mdl = Modules(aDoc.Name)
With mdl
etc.

See if that helps.

Jeff Bridgham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top