【问题标题】:MS Access 2013 to show only startup form and nothing elseMS Access 2013 仅显示启动表单,不显示其他内容
【发布时间】:2017-03-30 19:37:27
【问题描述】:

在启动我的 MS Access 2013 数据库时,我只需要它来显示启动表单而不需要其他任何东西。所需的结果将如下所示。背景是我的桌面。

期望:

但是,当我打开数据库时,表单会占据整个屏幕。

下面的 VBA 代码在启动表单加载时运行并且最初它可以工作,但是如果我最小化窗口,我可以再次看到背景。

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 Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long

Function fSetAccessWindow(nCmdShow As Long)
Dim loX As Long
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

我有隐藏的功能区、导航窗格和所有访问用户界面,但我还需要删除访问背景。

当前:

任何帮助/建议将不胜感激。提前谢谢!!!

【问题讨论】:

    标签: ms-access vba ms-access-2013


    【解决方案1】:

    您不需要任何 API 代码。

    以下设置应该可以解决问题:

    文件->选项->当前数据库

    取消选中“显示文档选项卡” 选择选项卡式文档。

    在上面还要取消选中显示导航窗格。

    要隐藏功能区,请在启动时执行这一行 VBA:

    DoCmd.ShowToolbar "Ribbon", acToolbarNo

    生成的屏幕将是这样的:

    确保表单不是对话框,并确保它们不是弹出表单。

    要返回“开发”模式,请退出数据库,然后按住 shift 键重新启动 - 这将绕过上述所有操作并允许您进行开发。

    【讨论】:

    • 如果你想拥有不同尺寸的不同形式怎么办?有没有办法让整个窗口用不同的形式重新调整大小?
    • 启动 Word、Excel、Web 浏览器永远不要重新调整应用程序窗口的大小。即使是具有 200 多种表格的会计系统也不会重新调整主应用程序窗口的大小。在过去的 20 年中,从未见过任何像您描述的那样工作的软件。应用程序的大小将采用启动的第一个表单的大小。对于我曾经使用过的 99% 的应用程序,主 UI 窗口在顶部或侧面提供菜单、选项卡或导航栏。也许可以根据启动的每个表单重新调整应用程序窗口的大小,但这是我以前从未见过的相当生涩和相当糟糕的 UI
    【解决方案2】:

    我使用主窗体和 Access 窗口大小的同步,因此 Access 窗口将始终位于主窗口后面。这是后面的代码:

    Private Sub Form_Resize()
    'main form
    'Let us know when Form is Maximized...
    
    If CBool(IsZoomed(Me.hwnd)) = True Then
        funSetAccessWindow (SW_SHOWMAXIMIZED)
        DoCmd.Maximize
        Me.TimerInterval = 0
    ElseIf CBool(IsIconic(Me.hwnd)) = True Then
        funSetAccessWindow (SW_SHOWMINIMIZED)
        Me.TimerInterval = 0
    Else
        'enable constant size sync
        Me.TimerInterval = 100
        SyncMainWindowSize Me, True
    End If
    End Sub
    
    Private Sub Form_Timer()
    SyncMainWindowSize Me
    End Sub
    
    Public Function SyncMainWindowSize(frm As Form, Optional blnForce As Boolean = False)
    Dim rctForm As RECT
    Dim iRtn As Integer
    Dim blnMoved As Boolean
    
    Static x As Integer
    Static y As Integer
    Static cx As Integer
    Static cy As Integer
    
    #If VBA7 And Win64 Then
        Dim hWndAccess As LongPtr
    #Else
        Dim hWndAccess As Long
    #End If
    
    If GetWindowRect(frm.hwnd, rctForm) Then
        If x <> rctForm.Left Then
            x = rctForm.Left
            blnMoved = True
        End If
    
        If y <> rctForm.Top Then
            y = rctForm.Top
            blnMoved = True
        End If
        If cx <> rctForm.Right - rctForm.Left Then
            cx = rctForm.Right - rctForm.Left
            blnMoved = True
        End If
        If cy <> rctForm.Bottom - rctForm.Top Then
            cy = rctForm.Bottom - rctForm.Top
            blnMoved = True
        End If
    
        If blnMoved Or blnForce Then
            'move/resize main window
            hWndAccess = Application.hWndAccessApp
            iRtn = apiShowWindow(hWndAccess, WM_SW_RESTORE)
            Call SetWindowPos(hWndAccess, 0, x, y, cx, cy, WM_SWP_NOZORDER Or WM_SWP_SHOWWINDOW)
        End If
    End If
    End Function
    
    Function funSetAccessWindow(nCmdShow As Long)
    'Usage Examples
    'Maximize window:
    '       ?funSetAccessWindow(SW_SHOWMAXIMIZED)
    'Minimize window:
    '       ?funSetAccessWindow(SW_SHOWMINIMIZED)
    'Hide window:
    '       ?funSetAccessWindow(SW_HIDE)
    'Normal window:
    '       ?funfSetAccessWindow(SW_SHOWNORMAL)
        Dim loX  As Long
        On Error GoTo ErrorHandler
    
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
        funSetAccessWindow = (loX <> 0)
    End Function
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 2015-02-22
      • 2022-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多