Ok, I've solved this...maybe a little unorthodox, but it works. If the DB seems to work after I reopen it, then I just figured I could program a restart, which, you wouldn't think would be possible since the code dies with the program. But there seems to be some sort of time delay the way I've got it so that it all works out. Anyway, here's what I've got:
a recap:
On my 'Main Menu' form, which loads on DB open, I've got this button that closes the whole DB, and another button that toggles to 'Developer View'. Once I switch to 'Developer View', I want my 'Developer View' button to change to a 'User View' button, and I want my 'close DB' button to change to a 'close window' button so that I can easily close the Main Menu and navigate through my objects with the NavPane. That part is easy; just overlay one button on another and switch between them using the 'Visible' property. Also, I want the shortcut menu to be available during 'Developer View', but not in 'User View', so that I can easily right-click on my forms to go to Design view, but the user can't. And finally, I wanted my Access main application window to go away for 'User View', but come back for 'Developer View'.
So here's the finished Module1 ( I had to tweak it for 64-bit by adding "PtrSafe" and changing Long to LongLong):
Code:
Option Compare Database
Option Explicit
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3
Private Declare PtrSafe Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hWnd As LongLong, _
ByVal nCmdShow As LongLong) As LongLong
Function fSetAccessWindow(nCmdShow As LongLong)
Dim loX As LongLong
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If Err <> 0 Then
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
MsgBox "Cannot minimize Access with " _
& (loForm.Caption + " ") _
& "form on screen"
ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
MsgBox "Cannot hide Access with " _
& (loForm.Caption + " ") _
& "form on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
fSetAccessWindow = (loX <> 0)
End Function
....and here's the finished Module2:
Code:
Option Compare Database
Sub Reopen()
Dim strPathName As String
strPathName = CurrentProject.Path & "\" & CurrentProject.Name
Dim accapp As Access.Application
Set accapp = New Access.Application
accapp.OpenCurrentDatabase (strPathName)
DoCmd.Quit acQuitSaveAll
End Sub
...and here's the code for the 'Main Menu':
Code:
Option Compare Database
Private Sub Developer_View_Button_Click()
DoCmd.Close acForm, "MainMenu", acSaveYes
DoCmd.OpenForm "Developer Password", acNormal, "", "", , acNormal
DoCmd.GoToControl "Password"
End Sub
Private Sub User_View_Button_Click()
DoCmd.Close acForm, "MainMenu", acSaveYes
'A version of the following needs written for every form in the DB:
'DoCmd.OpenForm "Double_click_here_to_change_name", acDesign, , , , acHidden
'Forms![Double_click_here_to_change_name].ShortcutMenu = True
'DoCmd.Close acForm, "Double_click_here_to_change_name", acSaveYes
DoCmd.OpenForm "Developer Password", acDesign, , , , acHidden
Forms![Developer Password].ShortcutMenu = False
DoCmd.Close acForm, "Developer Password", acSaveYes
DoCmd.OpenForm "MainMenu", acDesign, , , , acHidden
Forms![MainMenu].ShortcutMenu = False
DoCmd.Close acForm, "MainMenu", acSaveYes
DoCmd.OpenForm "MainMenu", acDesign, , , , acHidden
Forms![MainMenu].Developer_View_Button.Visible = True
Forms![MainMenu].[User View Button].Visible = False
Forms![MainMenu].[Close Window Button].Visible = False
Forms![MainMenu].[Close Access Button].Visible = True
DoCmd.Close acForm, "MainMenu", acSaveYes
DoCmd.OpenForm "MainMenu", acNormal, , , , acWindowNormal
Call fSetAccessWindow(0)
End Sub
...and here's what I've got in my Password form:
Code:
Option Compare Database
Private Sub Cancel_Button_Click()
DoCmd.Close acForm, "Developer Password", acSaveYes
DoCmd.OpenForm "MainMenu", acNormal, , , , acWindowNormal
End Sub
Private Sub Ok_Button_Click()
Dim strPasswd
strPasswd = Me.Password
If strPasswd = "whatever_your_password_is" Then
DoCmd.Close acForm, "Developer Password", acSaveYes
'A version of the following needs written for every form in the DB:
'DoCmd.OpenForm "Double_click_here_to_change_name", acDesign, , , , acHidden
'Forms![Double_click_here_to_change_name].ShortcutMenu = True
'DoCmd.Close acForm, "Double_click_here_to_change_name", acSaveYes
DoCmd.OpenForm "Developer Password", acDesign, , , , acHidden
Forms![Developer Password].ShortcutMenu = True
DoCmd.Close acForm, "Developer Password", acSaveYes
DoCmd.OpenForm "MainMenu", acDesign, , , , acHidden
Forms![MainMenu].ShortcutMenu = True
DoCmd.Close acForm, "MainMenu", acSaveYes
DoCmd.OpenForm "MainMenu", acDesign, , , , acHidden
Forms![MainMenu].[User View Button].Visible = True
Forms![MainMenu].[Developer View Button].Visible = False
Forms![MainMenu].[Close Window Button].Visible = True
Forms![MainMenu].[Close Access Button].Visible = False
DoCmd.Close acForm, "MainMenu", acSaveYes
Call fSetAccessWindow(1)
Run "Reopen"
Else
MsgBox "You do not have developer access", _
vbOKOnly, "Important Information"
DoCmd.Close acForm, "Developer Password", acSaveYes
DoCmd.OpenForm "MainMenu", acNormal, , , , acWindowNormal
Exit Sub
End If
End Sub
And that's it. I'm not sure why it works...I guess the part where it opens the current DB takes long enough that the command to quit get's done in time for it not to have the lock on.
Actually, I tried this at first in a separate 'Utility' DB...that is, run code to open a different DB then close, then in the other DB have code to open the first DB then close itself. But then I realized that it works all from within itself just fine...which is good, because then I don't have to pack around a separate DB just to make it work. Best part is, it returns it's own filepath so I don't have to change it if I install it somewhere else.
Anyway, there it is if anyone else needs it...and if anyone sees any potential problems, let me know.
thanks.