How to Hide Visual Basic Editor (VBE) Window Programmatically

  • Thread starter charles-guillaume.harika
  • Start date
C

charles-guillaume.harika

Hello world,

My problem :

I create in a module from db1 a new database db2 by the instruction:
DBEngine.CreateDatabase(Application.CurrentProject.Path &
"\Compacter.mdb", dbLangGeneral, False)

then I create from db1 a module (called "Comapcting") in the db2
thanks to:
objAccess.OpenCurrentDatabase Application.CurrentProject.Path &
"\Compacter.mdb", False
objAccess.DoCmd.RunCommand acCmdNewObjectModule
objAccess.DoCmd.Save acModule, objAccess.Modules(0).name
objAccess.DoCmd.Rename "Compacting", acModule,
objAccess.Modules(0).name

I write some code in this module by th instruction:
objAccess.Modules("Compacting").InsertText "code I want to appear in
the new module"

HERE is THE Problem: the command .InsertText open the VBE window of
the db2

I would like to know if it's possible to hide this VBE Window. I
already hide the main Access window with:
apiShowWindow(objAccess.hWndAccessApp, 0) '0 is the constant in order
to Hide the window

Do you know how to know the handle of the VBE window ? In this case I
would use the apiShowWindow function.
Or is there another way to hide the VBE window ?

I put here my entire code:

Option Compare Database

Public Declare Function apiShowWindow Lib "user32" Alias
"ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Public Function db_compact()
On Error GoTo Erreur

Dim objAccess As New Access.Application
Dim dbs As DAO.Database
Dim ref As Reference
Dim new_name As String
Dim tmp_name As String

Set dbs = DBEngine.CreateDatabase(Application.CurrentProject.Path &
"\Compacter.mdb", dbLangGeneral, False) 'Creation of the db2
dbs.Close
Set dbs = Nothing

objAccess.OpenCurrentDatabase Application.CurrentProject.Path &
"\Compacter.mdb", False
Call apiShowWindow(objAccess.hWndAccessApp, 0)

objAccess.DoCmd.RunCommand acCmdNewObjectModule 'Creation of a new
module in db2
objAccess.DoCmd.Save acModule, objAccess.Modules(0).name
objAccess.DoCmd.Rename "Compacting", acModule,
objAccess.Modules(0).name

objAccess.Modules("Compacting").InsertText "dadada" 'Inserting code in
the created module of db2
objAccess.DoCmd.Save acModule, "Compacting"

objAccess.DoCmd.Close acModule, "Compacting", acSaveYes

objAccess.CloseCurrentDatabase
Set objAccess = Nothing
Erreur:
End Function
 
S

storrboy

I might have something for you to try and work with. I don't have the
scenario you do where the editor opens while other code is running so
it's hard for me to test it.
The idea is to call a function like below immediatley after the line
in yours that causes the window to open. I'm hoping this will become
the "Active Window" and as such be able to get it's Hwnd the easy way.
The problem is that continuing to affect the window may cause it to
restore, as happens when I try to test it from the editor. Maybe this
will give you a starting point?


Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long

Private Const SW_HIDE As Long = 0
Private Const SW_RESTORE As Long = 9
Private Const SW_MINIMIZE As Long = 6


Function HideVBE(Optional UnHideWindow As Boolean _
= False) As Boolean
On Error GoTo stoprun
Dim hwndVBE As Variant
Dim wndwState As Long

HideVBE = False

hwndVBE = GetActiveWindow
If IsNull(hwndVBE) And hwndVBE <> 0 Then
MsgBox "There is no window to affect"
Exit Function
End If

If UnHideWindow Then wndwState = SW_RESTORE Else _
wndwState = SW_HIDE
ShowWindow hwndVBE, wndwState
HideVBE = True

Exit_Here:
Exit Function

stoprun:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Here

End Function
 
C

charles-guillaume.harika

Thank you for your response,

I will try this option and see what are the issues.

Regards.

Charles
 

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