如何动态调整连续对话框的大小以适合/显示所有记录

解决Access2010中连续对话框默认占据整个屏幕高度的问题,通过代码动态调整表单大小以适应记录数量,同时控制滚动条显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我最近遇到一个问题,我打开一个连续对话框,显示从1到X的任何记录,X通常在2-5范围内。 我发现非常烦人的是,Access2010的默认设置使continue表单占据了整个屏幕高度,即使只有很少的记录也是如此。

因此,为了解决该问题,我想出了一些代码来使窗口大小与记录数量大致匹配,并能够指定要显示的最大记录数量。 如果记录量超过了最大值,我还将使用代码来修改滚动条设置,以便仅当记录数超过最大值时才显示滚动条。

代码如下所示,我将其放置在表单的Load事件中:

Private Sub Form_Load()
   'Variables
      Dim lngCount As Long
      Dim lngWindowHeight As Long
      Dim lngOldWindowHeight As Long
      Dim lngDeltaTop As Long
      Dim lngMaxRecordsToShow As Long 
      lngMaxRecordsToShow = 10 
   'Find the amount of records in form
      Dim rs As DAO.Recordset
      Set rs = Me.RecordsetClone
      If Not rs.EOF Then rs.MoveLast
      lngCount = rs.RecordCount 
   'Check whether there are more then Max amount of records
      If lngCount > lngMaxRecordsToShow Then
         lngCount = lngMaxRecordsToShow
         'Enable vertical scrollbar
            Me.ScrollBars = 2 'Vertical
      Else
         'Disable scrollbars
         Me.ScrollBars = 0 'None
      End If 
   'Calculate new windowheight.
   'If you do not have a header/footer, or they are not visible adjust accordingly
      lngWindowHeight = Me.FormHeader.Height + _
                  Me.Detail.Height * lngCount + _
                  Me.FormFooter.Height + _
                  400
                  'The 567 is to account for title bar Height.
                  'If you use thin border, adjust accordingly 
   'The form will be "shortened" and we need to adjust the top property as well to keep it properly centered
      lngOldWindowHeight = Me.WindowHeight
      lngDeltaTop = (lngOldWindowHeight - lngWindowHeight) / 2 
   'Use the move function to move the form 
      Me.Move Me.WindowLeft, Me.WindowTop + lngDeltaTop, , lngWindowHeight 
   'Cleanup
      Set rs = Nothing
End Sub
我用:

AutoRezise =真

AutoCenter =真

这段代码。 如果不这样做,可能会出现奇怪的结果,但是您可以自己进行测试。

From: https://bytes.com/topic/access/insights/943458-how-dynamically-resize-continuous-dialog-form-fit-show-all-records

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值