Hi Petrol.
There are many ways to achieve this in Access but fundamentally they come down to setting the flag to allow closing when you need to switch into Design mode & don't want the database to close down completely. Alternatively, you may want a separate flag set that allows switching explicitly. I'm going to assume that you don't want your users being able to take advantage of this.
So, in the absence of any code posted I'll assume your setup is very similar to what I will show, but with some minor, but important, changes.
Let's start with the dimensioning code in one of your standard modules :
- Public blnAllowClose As Boolean
-
Public blnAllowDesign As Boolean
I assume you already have the first, or similar, but the second is an addition.
In your switchboard code you'll need something like :
- Private Sub Form_Unload(Cancel As Integer)
-
If Not blnAllowClose _
-
And Not blnAllowClose Then
-
Cancel = True
-
Exit Sub
-
End If
-
End Sub
Clearly you already have code behind your "Exit Database" button that handles setting
blnAllowClose
(or your equivalent flag) so we're just left now with the harder bit of managing to set
blnAllowDesign
in such a way that only you have access to it.
One reliable way in most circumstances is to use the
UserName or
Account ID as returned by the operating system. You can see more on this at
Function to Return UserName (NT Login) of Current User. This would be my recommendation as long as it is reliable for you. One reason it might not be is, say, if a family member were using the database using your
Account ID. In most cases though this works well. In such a case
blnAllowDesign
would be unnecessary and the earlier code would become :
- Private Sub Form_Unload(Cancel As Integer)
-
If Not blnAllowClose _
-
And (sys_OrigUserID() <> "{YourAccountID}") Then
-
Cancel = True
-
Exit Sub
-
End If
-
End Sub
If this doesn't work for you then an alternative is to define a place on your switchboard that is known only to you and capture an Event based on that Control or area of the Form. For instance, say you had a Control on your Form with foreground = background, so essentially invisible, and you captured the Double-Click Event on that Control you may have some code such as below to handle silently switching between allowing Design Mode and disallowing it :
- Private Sub lblInvisible_DblClick(Cancel As Integer)
-
blnAllowDesign = (Not blnAllowDesign)
-
End Sub
This is based on the principle that only you would know to do that so all others would be blocked from switching to design mode.