patriciaxxx
Programmer
I am trying to get 2 lists one is custom menus and the other is custom shortcut menus from any external MS Access database I connect to (all versions and mdb, mde etc.).
The problem is:
The external database must remain hidden whilst the data is being collected ie. It must never be shown.
I have tried the following code in MS Access 2000 and 2003 and it works to a point. But sometimes the database shows until the code completes whilst a different database might not show depending on what forms and startup options are set. I just need a method to collect the menu data without the external database ever showing whatever its settings might be.
Option Compare Database
Option Explicit
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Sub test()
Dim sw As Long
Dim app As Object
Set app = CreateObject("Access.Application")
'app.Visible = False 'I have tried this line but it make no difference
Dim strpath As String
'strpath = "C:\mydb97.mdb"
strpath = "C:\mydb2k.mdb"
'strpath = "C:\mydb23k.mdb"
'strpath = "C:\mydb.mde"
sw = ShowWindow(app.hWndAccessApp, False)
app.OpenCurrentDatabase strpath
Dim m As String
Dim sm As String
Dim sCmdBar As CommandBar
For Each sCmdBar In app.CommandBars
Select Case True
Case sCmdBar.BuiltIn = False And sCmdBar.Type = 1
m = m & sCmdBar.Name & ";"
Case sCmdBar.BuiltIn = False And sCmdBar.Type = 2
sm = sm & sCmdBar.Name & ";"
End Select
Next
app.Quit
Set app = Nothing
strStartUpMenuBar.RowSourceType = "Value List"
strStartUpMenuBar.RowSource = m
strStartUpShortcutMenuBar.RowSourceType = "Value List"
strStartUpShortcutMenuBar.RowSource = sm
End Sub
The problem is:
The external database must remain hidden whilst the data is being collected ie. It must never be shown.
I have tried the following code in MS Access 2000 and 2003 and it works to a point. But sometimes the database shows until the code completes whilst a different database might not show depending on what forms and startup options are set. I just need a method to collect the menu data without the external database ever showing whatever its settings might be.
Option Compare Database
Option Explicit
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Sub test()
Dim sw As Long
Dim app As Object
Set app = CreateObject("Access.Application")
'app.Visible = False 'I have tried this line but it make no difference
Dim strpath As String
'strpath = "C:\mydb97.mdb"
strpath = "C:\mydb2k.mdb"
'strpath = "C:\mydb23k.mdb"
'strpath = "C:\mydb.mde"
sw = ShowWindow(app.hWndAccessApp, False)
app.OpenCurrentDatabase strpath
Dim m As String
Dim sm As String
Dim sCmdBar As CommandBar
For Each sCmdBar In app.CommandBars
Select Case True
Case sCmdBar.BuiltIn = False And sCmdBar.Type = 1
m = m & sCmdBar.Name & ";"
Case sCmdBar.BuiltIn = False And sCmdBar.Type = 2
sm = sm & sCmdBar.Name & ";"
End Select
Next
app.Quit
Set app = Nothing
strStartUpMenuBar.RowSourceType = "Value List"
strStartUpMenuBar.RowSource = m
strStartUpShortcutMenuBar.RowSourceType = "Value List"
strStartUpShortcutMenuBar.RowSource = sm
End Sub