Hide Access window and only show switchboard form

ej256

Registered User.
Local time
Today, 15:24
Joined
Jul 21, 2016
Messages
16
I have a simple database that around 20 people are going to be entering data into. I'm trying to simplify this as much as possible to reduce the amount of problems they might run into. I have a switchboard form that gives the users everything they need to interact with (four forms and three reports) that I run on startup. I want to just show this switchboard form and nothing else to the users. I found a really nice piece of code that accomplishes this which has been referenced in these forums multiple times and can seen here:

Code:
'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3


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

Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
'       ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
'       ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
'       ?fSetAccessWindow(SW_HIDE)
'Normal window:
'       ?fSetAccessWindow(SW_SHOWNORMAL)
'
Dim loX  As Long
Dim loForm As Form
    On Error Resume Next
    Set loForm = Screen.ActiveForm
    If Err <> 0 Then 'no Activeform
      If nCmdShow = SW_HIDE Then
        MsgBox "Cannot hide Access unless " _
                    & "a form is on screen"
      Else
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
        Err.Clear
      End If
    Else
        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
    End If
    fSetAccessWindow = (loX <> 0)
End Function

'************ Code End **********

I have this pasted into a module, and on startup I call fSetAccessWindow(SW_HIDE). The only problem that I have run into is I'm not able to open any reports from my switchboard. Forms work perfectly, but reports don't open at all. Access ends up freezing up and I have to go into the task manager and end the program. I've tried numerous work arounds included using the fSetAccessWindow(SW_SHOWMAXIMIZED) function call when opening any report, but that doesn't work either as access gets really weird when closing the report. I also have all my reports set as popup and modal.

Does anybody know how to modify this piece of code so I could have the same functionality with reports as I do with forms? Or does anybody know of another solution? This isn't really a game changer for my database as I have the database closing once the startup form (which is popup and module) closes meaning the users can already only interact with the switchboard form, but being able to hide the stuff would make it even cleaner.
 
Last edited:
all forms and reports need to be modal and popup if you want to see them without the access window
 
all forms and reports need to be modal and popup if you want to see them without the access window

I have them all as modal and popup.
 
interesting - I changed a report to popup/modal and even with the access window it froze. Not come across this before, not sure if there is anyone else out there with an explanation.

Assuming you are on 2007 or later, a workaround is to create a blank form set to popup/modal (you only need the one). Drag one of your reports onto it as a subform. You will need some vba code to resize the subform to the size of your form in the form resize event

Code:
 subformname.move 0,0,insidewidth, insideheight

then to show different reports use vba code to change the subform source object to other reports - e.g. say you pass the report name in the openform openargs parameter, in the form open event put

Code:
 subformname.sourceobject="report." & me.openargs
Obviously becomes a bit more complicated if also passing criteria. for this I would set the openargs for the openform to

reportname & "|" & strCriteria

and in the form open event

Code:
 dim prm() as string
 prm=split(me.openargs,"|")
 subformname.sourceobject="report." & prm(0)
 subformname.form.filter=prm(1)
 subformname.form.filteron=true
 
interesting - I changed a report to popup/modal and even with the access window it froze. Not come across this before, not sure if there is anyone else out there with an explanation.
No problem here!
 
think I found the problem - the report was popping up on a screen which was no longer connected and since it was modal, control could not be passed back to access . Changing the report autocentre property to yes solved the problem
 

Users who are viewing this thread

Back
Top Bottom