屏幕對象的屬性的ActiveForm具有類型的抽象類(「表」)的。
錯誤消息告訴你,Show方法將需要對從Form派生的具體類的實例的引用。這就像記載:
If you plan to pass Screen.ActiveForm or MDIForm.ActiveForm to a procedure, you must declare the argument in that procedure with the generic type (As Form) rather than a specific form type (As MyForm) even if ActiveForm always refers to the same type of form.
因此,解決方法是將申報所需的基於表單類型的變量,將其設置爲Screen.ActiveForm,然後用你的顯示調用對象的引用。
在這裏,我們有:
Option Explicit
'
'Form1 code
'
Private Sub Command1_Click()
Load Form2 'This is not the class Form2, but the predeclared instance named Form2.
End Sub
和:
Option Explicit
'
'Form2 code
'
Private Sub Form_Load()
'Use a Timer to defer the Show until after we've returned control to Form1:
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim Owner As Form1 'This is the class Form1, not the predeclared instance named Form1.
Timer1.Enabled = True
Set Owner = Screen.ActiveForm
Show vbModal, Owner
End Sub
似乎只是按預期工作和記錄,但我不知道爲什麼有人會需要做到這一點。
爲什麼不直接在Form1的Form1代碼中調用Form2?
您是否嘗試添加一些日誌記錄來檢查發生錯誤時的Screen.ActiveForm。將這些表達式寫入一個文本文件:'((Screen.ActiveForm是Nothing)',並且在一個單獨的代碼行中,以防發生錯誤'Screen.ActiveForm.Name' – MarkJ 2014-11-24 16:18:35
Screen.ActiveForm可能不是您認爲的那樣嗎?它運行在某種終端會話上嗎? – Rob 2014-11-24 18:03:52