admin管理员组

文章数量:1794759

Access开发之只显示窗体

Access开发之只显示窗体

作为程序的小白,想快速开发一个程序作为工作工程中使用,面对的数据量有个几万行的数据,要是用Excel的化,太慢,经常容易出现异常崩溃,所以,直接使用Access进行简单的开发一个局域网的共享数据库,希望使用软件的界面进行操作,这样好用点。 进入主题, 学习ACCESS的过程中,需要置显示窗体,而 不显示其他的内容,那么,操作如下: 实现的逻辑,首先打开ACCESS的时候显示窗体,显示的时候将导航以及其他的界面最小化,然后定义为只显示该窗体。步骤如下: 1.Access打开的时候显示对应的界面 这个比较简单百度以下就知道了。。。这里略过。 2.在首先出现的代码中增加如下:

Private Sub Form_Load() DoCmd.RunCommand acCmdAppMinimize ' 开始显示的时候,将窗体最小化 WindowToTop Me.Hwnd, True‘显示的时候,将窗体置顶 End Sub Private Sub Form_Current() '......隐藏窗体 show_hide (0) End Sub Private Sub Form_Unload(Cancel As Integer) show_hide (2) 'show the window.show_hide (0)2020.06.03 End Sub

3.Modules中插入模块,模块中加入定义的函数show_hide()和声明,代码如下

Option Compare Database Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal Hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Option Explicit Private Declare Function ShowWindow Lib "user32" _ (ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long Function show_hide(nCmdShow As Long) On Error Resume Next Dim loFORM As Form 'hide the window, and the form ,but have the issue Set loFORM = Screen.ActiveForm If Err <> 0 Then ' no ActiveFORM If nCmdShow = 0 Then MsgBox "Cannot hide Access unless" Else ShowWindow Application.hWndAccessApp, nCmdShow Err.Clear End If Else ShowWindow Application.hWndAccessApp, nCmdShow End If End Function

同时增加产品最前端显示的声明,可以放在一起也可以独立

Option Compare Database Public Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal Hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPtr Function WindowToTop(Hwnd As LongPtr, OnTop As Boolean) If OnTop Then SetWindowPos Hwnd, -1, 0, 0, 0, 0, &H3 Else SetWindowPos Hwnd, -2, 0, 0, 0, 0, &H3 End If End Function Public Declare Function SetWindowPos Lib "user32" (ByVal Hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Function WindowToTop(Hwnd As Long, OnTop As Boolean) If OnTop Then SetWindowPos Hwnd, -1, 0, 0, 0, 0, &H3 Else SetWindowPos Hwnd, -2, 0, 0, 0, 0, &H3 End If End Function

特别需要说明的事,在很多的软件中,会又很多的界面进行切换,如果需要使用到窗体的切换,需要在每个窗体中增加如下代码:

Private Sub Form_Current() show_hide (0) 'hide the window.show_hide (0)2020.06.03 WindowToTop Me.Hwnd, False End Sub Private Sub Form_Load() WindowToTop Me.Hwnd, True End Sub Private Sub Form_Unload(Cancel As Integer) show_hide (2) 'show the window.show_hide (0)2020.06.03 End Sub

这样就可以实现界面的切换。

本文标签: 窗体只显示Access