habennin
08-17-2007, 12:33 AM
Hi,
I think this is a basic task but I can't figure it out. I have a situation where I change a record in a table and I want to reset all of the combo boxes that draw on that table source through absolutely all open forms and subforms. Unfortunately some of my subforms have subforms have subforms. That's ugly but it's the way it is. I have written a code that will go through all open forms and their subforms. How can I take this to the n+ level? Any advice is much appreciated.
Dim frm As Form, intI As Integer
Dim intJ As Integer
Dim intK As Integer
Dim intControls As Integer, intForms As Integer
Dim intsubControls As Integer
Dim subfrm As Form
intForms = Forms.Count ' Number of open forms.
If intForms > 0 Then
For intI = 0 To intForms - 1
Set frm = Forms(intI)
Debug.Print frm.Name
intControls = frm.Count
If intControls > 0 Then
For intJ = 0 To intControls - 1
If (frm(intJ).Name = "region_id") Then
frm(intJ).RowSource = "SELECT region_name, region_id FROM region ORDER BY region_name;"
End If
If (TypeOf frm(intJ) Is SubForm) Then
intsubControls = frm(intJ).Form.Count
Set subfrm = frm(intJ).Form
For intK = 0 To intsubControls - 1
If (subfrm(intK).Name = "region_id") Then
subfrm(intK).RowSource = "SELECT region_name, region_id FROM region ORDER BY region_name;"
End If
Debug.Print subfrm.Controls(intK).Name
Next intK
Debug.Print intsubControls
End If
Debug.Print frm(intJ).Name
Next intJ
End If
Next intI
Else
MsgBox "No open forms.", vbExclamation, "Form Controls"
End If
I think this is a basic task but I can't figure it out. I have a situation where I change a record in a table and I want to reset all of the combo boxes that draw on that table source through absolutely all open forms and subforms. Unfortunately some of my subforms have subforms have subforms. That's ugly but it's the way it is. I have written a code that will go through all open forms and their subforms. How can I take this to the n+ level? Any advice is much appreciated.
Dim frm As Form, intI As Integer
Dim intJ As Integer
Dim intK As Integer
Dim intControls As Integer, intForms As Integer
Dim intsubControls As Integer
Dim subfrm As Form
intForms = Forms.Count ' Number of open forms.
If intForms > 0 Then
For intI = 0 To intForms - 1
Set frm = Forms(intI)
Debug.Print frm.Name
intControls = frm.Count
If intControls > 0 Then
For intJ = 0 To intControls - 1
If (frm(intJ).Name = "region_id") Then
frm(intJ).RowSource = "SELECT region_name, region_id FROM region ORDER BY region_name;"
End If
If (TypeOf frm(intJ) Is SubForm) Then
intsubControls = frm(intJ).Form.Count
Set subfrm = frm(intJ).Form
For intK = 0 To intsubControls - 1
If (subfrm(intK).Name = "region_id") Then
subfrm(intK).RowSource = "SELECT region_name, region_id FROM region ORDER BY region_name;"
End If
Debug.Print subfrm.Controls(intK).Name
Next intK
Debug.Print intsubControls
End If
Debug.Print frm(intJ).Name
Next intJ
End If
Next intI
Else
MsgBox "No open forms.", vbExclamation, "Form Controls"
End If