Access打开指定弹出式窗体

源码示例分享!Access打开指定弹出式窗体,并将其定位在当前控件下方。

'经修改Access网友的源码而来

'函数名称: OpenFormFor

'frmName:,必选参数,需要打开的窗体名称
'功能描述: 打开一个弹窗式窗体定位到当前活动窗体活动控件

'2022-08-13更新了一下代码

Public Function OpenFormFor(frmName As String, Optional strArgs As String, Optional lngX As Long = 0, Optional lngY As Long = 0)
On Error GoTo Err_OpenFormFor
Dim lngLeft As Long
Dim lngTop As Long
Dim lngWidth As Long
Dim lngHeight As Long
Dim lngBorderWidth As Long
Dim CurrentCtl As Control

With Screen.ActiveForm
Dim frm As Object
'获取当前活动窗体控件名称
For Each frm In CurrentProject.AllForms
Set CurrentCtl = Screen.ActiveForm.ActiveControl
Next frm
'计算窗体左右边框宽度
lngBorderWidth = (.WindowWidth - .InsideWidth) / 2
lngLeft = .WindowLeft + CurrentCtl.Left
'判断是否有记录选择器
If .RecordSelectors Then lngLeft = .WindowLeft + .WindowWidth - .InsideWidth + CurrentCtl.Left - CurrentCtl.BottomPadding / 2
'====================
lngHeight = (.WindowHeight - .InsideHeight - lngBorderWidth)
'计算定位的Y位置
lngTop = .WindowTop + CurrentCtl.Top + CurrentCtl.Height + lngHeight / 2 + lngBorderWidth - CurrentCtl.BottomPadding
'判断活动控件位置在窗体页眉或页脚位置
Select Case CurrentCtl.Section
Case acDetail
lngTop = lngTop + .Section(acHeader).Height
Case acFooter
lngTop = lngTop + .Section(acHeader).Height + .Section(acDetail).Height
End Select
'打开指定窗体,strArgs传递参数
DoCmd.OpenForm frmName, , , , , , strArgs
'定位打开窗体到活动窗体控件,lngX,lngY微调补正位置
Forms(frmName).Move lngLeft + lngX, lngTop + lngY
End With

Exit_OpenFormFor:
Exit Function

Err_OpenFormFor:
If Err = 2462 Then
Resume Next
Else
MsgBox Err.Description, vbCritical, "Error For Function OpenFormFor"
Resume Exit_OpenFormFor
End If
End Function


演 示:


示例下载:

Access打开指定弹出式窗体,并将其定位在当前控件下方的示例,Access窗体定位【Access软件网】

展开阅读全文

页面更新:2024-03-12

标签:弹出式   窗体   页眉   边框   示例   控件   源码   位置   名称   参数

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top