2012-10-22 66 views
1

我有一個帶有子窗體的窗體,它們通過ID鏈接。問題是子窗體有一個組合框,需要來自主窗體的主窗體的參數。從主窗體中帶參數的子窗體

表單是關於銷售電話,他們需要能夠鏈接許多建議和合同,因爲他們想要的。提案和合同清單的組合框需要與該銷售電話的工廠或客戶有關。

我知道我可以做一個Forms!FormName!ControlName來獲得磨機列表,但這是否意味着我有設計問題?

或者我應該做一個列表填充當用戶點擊主窗體組合框中的一個元素?但後來我不得不處理保存並刪除自己。

謝謝

+0

「!窗體名稱窗體控件名稱來獲得磨名單但這是否意味着我有一個設計問題,」我不明白爲什麼你應該有一個問題。每一行都是指主表單,所以你應該沒問題。 – Fionnuala

+0

我以爲子窗體必須獨立於主窗體,因此您可以將它用於多個主窗體(不在我的情況下) – Marc

+1

不,如果您擔心它,您可以檢查子表單,它有一個父母,並取消打開,如果沒有。 – Fionnuala

回答

1

如果子窗體需要主窗體才能正常工作,則可以檢查父窗體。例如:

Private Sub Form_Open(Cancel As Integer) 
Dim strParent As String 
Dim strSubname As String 

    GetParent Me, strParent, strSubname 

    If strParent = "None" Then 
     MsgBox "This is not a stand-alone form.", , "Form Open Error" 
     Cancel = True 
    End If 
End Sub 

Function GetParent(frm, ByRef strParent, ByRef strSubname) 
Dim ctl 

On Error Resume Next 
    strParent = frm.Parent.Name 
    If Err.Number = 2452 Then 
     Err.Clear 
     strParent = "None" 
    Else 
     For Each ctl In frm.Parent.Controls 
      If ctl.ControlType = acSubform Then 
       If ctl.SourceObject = frm.Name Then 
        strSubname = ctl.Name 
       End If 
      End If 
     Next 
    End If 

End Function