Hi all! Back again with another of my weird questions. It's a bit of a mix of VBA code, forms, reports and access in general so I'll put it in here. Any admin feel free to move it if it suits another section better.
Thing is, I have developed an inventory database in Access with the Access interface visible for simple commodity while programming and designing it, but with the idea of hiding it afterwards and making the user work through the forms and not let them get their hands on the tables directly. Unfortunately I have recently discovered that report previews won't show with the access interface hidden. I need to show a preview because depending on the records fitting a search criteria, the report might span several pages and I want to let the users check the report before deciding they want to go ahead and print it. All forms and reports are modal pop-ups, meaning the report appears hidden (because of the hidden interface) but blocks the access to the rest of the elements, forcing to shut the application by the task manager.
This is the code I'm using to hide the UI:
Code:
Option Compare Database
'Guarda Valor de Estados de Ventana
Dim dwReturn As Long
'Constantes de Estado de Ventana
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
' Se identifica Plataforma 32 o 64 bits'
#If Win64 Then
Private Declare PtrSafe Function IsWindowVisible Lib "User32" (ByVal hwnd As Long) As Long
Private Declare PtrSafe Function ShowWindow Lib "User32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
#Else
Private Declare Function IsWindowVisible Lib "User32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "User32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
#End If
'Llamada de funcion para ocultar Ventana de Access
Public Function fAccessWindow(Optional Procedure As String, Optional SwitchStatus As Boolean, Optional StatusCheck As Boolean) As Boolean
'Tres Modos de llamada de Ventana: Ocultada, Visible, Minimizada
If Procedure = "Hide" Then
dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
End If
If Procedure = "Show" Then
dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
End If
If Procedure = "Minimize" Then
dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMINIMIZED)
End If
If SwitchStatus = True Then
If IsWindowVisible(hWndAccessApp) = 1 Then
dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
Else
dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
End If
End If
If StatusCheck = True Then
If IsWindowVisible(hWndAccessApp) = 0 Then
fAccessWindow = False
End If
If IsWindowVisible(hWndAccessApp) = 1 Then
fAccessWindow = True
End If
End If
End Function
The autoexec form has the following on its onLoad event
Code:
fAccessWindow "Hide", False, False
Then I open the report with a simple OpenReport, as an example
Code:
DoCmd.OpenReport "Oficina_Movil", acViewPreview, , "[Id_oficina]='" & Me.Id_Oficina & "'"
The modal pop-up behaviour must remain (it's not specified on the OpenReport instruction because it's set up in the report properties).
Want to try to solve that without any external program or plugin like snapshot viewer, and the only workaround I've found is showing the Access interface before opening the report, then hiding it again when closing the report. So now the OperReport looks like:
Code:
fAccessWindow "Show", False, False
DoCmd.OpenReport "Oficina_Movil", acViewPreview, , "[Id_oficina]='" & Me.Id_Oficina & "'"
And the Close event of the report has the instruction to hide the interface again. This works as intended, the report shows and the interface hides again when closing it, but the form from which the report was invoked becomes irresponsive.
Ive tried:
Code:
Forms(Forms.Count-1).setFocus
and
Code:
Forms(Forms.Count-1).visible=true
Both seem to get the focus on the form, but it remains irresponsive, so I can't click anything and once again, since the forms are popup and modal too, I have to kill the app.
Any insight on how to return the control to the calling form after hiding the interface again?