2017-01-12 76 views
0

我試圖通過使用某些動畫打開子表單來爲我的Access數據庫添加一點耀斑。我希望它從主窗體的左上角打開,並以小增量擴大其大小,直到達到主窗體的寬度和高度。當我逐步瀏覽代碼時,我的代碼似乎可以正常工作,但實際上,它在整個循環期間暫停,並且只顯示全尺寸而沒有任何動畫外觀的表單。看起來好像它在批處理中運行循環,然後執行對子窗體對象的調整。有關如何實現這一目標的任何建議?使用Access VBA動畫化子表格

Option Compare Database 
Option Explicit 

Declare Sub Sleep Lib "kernel32" _ 
(ByVal dwMilliseconds As Long) 

Public Sub AnimateOpenForm(SubForm As String, maxWidth As Long, maxHeight As Long) 
    Dim sbf As SubForm 
    Dim parentForm As String 
    Dim incrementX As Double 
    Dim incrementY As Double 

    parentForm = "frmHome" 

    Set sbf = Forms(parentForm).Controls("sbfPopUp") 
    sbf.SourceObject = SubForm 

    sbf.Width = 0 
    sbf.Height = 0 

    sbf.Visible = True 

    incrementX = maxWidth/1000 
    incrementY = maxHeight/1000 

    Do While sbf.Width < maxWidth And sbf.Height < maxHeight 

     sbf.Width = sbf.Width + incrementX 
     sbf.Height = sbf.Height + incrementY 

     Sleep 10 

    Loop 

End Sub 
+0

啊哈!我在循環中添加了sbf.requery,現在它運行得很漂亮。總是想念這個小事... –

回答

0

DoEvents會爲系統提供所需的重新暫停。我改變你的代碼從「睡眠10」到「開始=定時器:做:DoEvents:循環直到定時器 - 開始> = 0.001」 和向上頂部Dim' ed「Dim started As Single」導致:

 


Public Sub AnimateOpenForm(SubForm As String, maxWidth As Long, maxHeight As Long) 
    Dim sbf As SubForm 
    Dim parentForm As String 
    Dim incrementX As Double 
    Dim incrementY As Double 
    Dim started As Single 

    parentForm = "frmHome" 

    Set sbf = Forms(parentForm).Controls("sbfPopUp") 
    sbf.SourceObject = SubForm 

    sbf.Width = 0 
    sbf.Height = 0 

    sbf.Visible = True 

    incrementX = maxWidth/1000 
    incrementY = maxHeight/1000 

    Do While sbf.Width < maxWidth And sbf.Height $lt; maxHeight 

     sbf.Width = sbf.Width + incrementX 
     sbf.Height = sbf.Height + incrementY 

     started = Timer: Do: DoEvents: Loop Until Timer - started >= 0.001 

    Loop 

End Sub