Keeping VB window closed.

M

mcescher

Hi All,

Apologies for the multipost, but I was in the wrong newgroup when I
initially posted.

I am trying to read some information from the modules in a database.
My function opens the module and then counts the procedures in it, then

it closes the module.


DoCmd.OpenModule strModule
Set mdf = Modules(strModule)
For intX = 1 To mdf.CountOfLines
If ((InStr(mdf.Lines(intX, 1), "Sub")) Or _
(InStr(mdf.Lines(intX, 1), "Function"))) And _
((InStr(mdf.Lines(intX, 1), "End")) = 0) Then
If Not blnShowDef Then
If blnShow Then Debug.Print Left(mdf.Lines(intX, 1),
InStr(mdf.Lines(intX, 1), "(") - 1)
Else
If blnShow Then Debug.Print mdf.Lines(intX, 1)
End If
intCount = intCount + 1
End If
Next intX
DoCmd.Close acModule, strModule, acSaveNo


Running this code from a form opens the Visual Basic window on top of
Access. Can I code it to not show the VB window?


Thanks,
Chris M.
 
M

Marshall Barton

mcescher said:
Hi All,

Apologies for the multipost, but I was in the wrong newgroup when I
initially posted.

I am trying to read some information from the modules in a database.
My function opens the module and then counts the procedures in it, then

it closes the module.


DoCmd.OpenModule strModule
Set mdf = Modules(strModule)
For intX = 1 To mdf.CountOfLines
If ((InStr(mdf.Lines(intX, 1), "Sub")) Or _
(InStr(mdf.Lines(intX, 1), "Function"))) And _
((InStr(mdf.Lines(intX, 1), "End")) = 0) Then
If Not blnShowDef Then
If blnShow Then Debug.Print Left(mdf.Lines(intX, 1),
InStr(mdf.Lines(intX, 1), "(") - 1)
Else
If blnShow Then Debug.Print mdf.Lines(intX, 1)
End If
intCount = intCount + 1
End If
Next intX
DoCmd.Close acModule, strModule, acSaveNo


Running this code from a form opens the Visual Basic window on top of
Access. Can I code it to not show the VB window?


I think you need to use the Echo method to prevent the
screen from being updated. This can be a disaster if you
forget (or an error prevents) to turn echo back on. Try
using logic like:

Public Sub CountProcs(strModule As String)
On Error GoTo ErrHandler
Application.Echo False

your code goes here

OutOfHere:
Application.Echo True
Exit Sub

ErrHandler:
MsgBox Err.Number & " - " & Err.Description
Resume OutOfHere
End Sub

Check VBA Help for details, especially the part about
creating a hotkey macro that turns echo back on when things
go bonkers.
 
J

John Spencer

Marshall,
If you do get an error will the Msgbox appear? I always thought you had to
put Application.Echo True in the error handler before calling the msgbox
function.

Public Sub CountProcs(strModule As String)

' Code here


Exit Sub

ErrHandler:
Application.Echo True
MsgBox Err.Number & " - " & Err.Description
Resume OutOfHere

End Sub
 
D

Douglas J. Steele

I don't think it's necessary, John.

Try running the following code:

Application.Echo False
MsgBox "This should appear, even though Echo is off"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


John Spencer said:
Marshall,
If you do get an error will the Msgbox appear? I always thought you had
to put Application.Echo True in the error handler before calling the
msgbox function.

Public Sub CountProcs(strModule As String)

' Code here


Exit Sub

ErrHandler:
Application.Echo True
MsgBox Err.Number & " - " & Err.Description
Resume OutOfHere

End Sub
 
J

John Spencer

Thanks.

You are correct.

I am just paranoid about making sure. I should have tested before posting.


Douglas J. Steele said:
I don't think it's necessary, John.

Try running the following code:

Application.Echo False
MsgBox "This should appear, even though Echo is off"
 
M

Marshall Barton

As Doug said, it does appear. According to Help, Echo does
not apply to dialog boxes.

A side note, John. I tried to email you and am wondering if
I used the wrong address, got caught in a spam trap, or
what. If you have the time, email me so we can catch up
with each other.
 
M

mcescher

Marshall said:
As Doug said, it does appear. According to Help, Echo does
not apply to dialog boxes.

A side note, John. I tried to email you and am wondering if
I used the wrong address, got caught in a spam trap, or
what. If you have the time, email me so we can catch up
with each other.
 
M

mcescher

Sorry guys, but this did not solve it. Any other suggestions?

Thanks a bunch,
Chris
 
M

Marshall Barton

I'm sorry too. I'm pretty sure that used to work, but it
sure doesn't anymore. Probably has something to do with VBE
being separated from Access and having its own window. The
best I could do was to make the VBE window pretty small
before closing it. Then when it opens, it doesn't cover
everything else, a pain, but, without trying to find some
kind of API solution, I don't think this behavior can be
prevented anymore.
 

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