-
oki dokey, one more question...
I've got a form with 200+ controls (don't ask :) .) I've created a class to loop through all the controls on the form and save their values to an .ini file. I'm only interested in saving textboxes, combo lists, etc. - not every control.
How should I go about determining what type of control a control is?
Thanks a million!
-
Code:
Private Sub Command1_Click()
Dim MyControl As Control
Dim iList As Integer
For Each MyControl In Me.Controls
If TypeOf MyControl Is TextBox Then
'save code
Open "C:\MyFile.txt" For Append As #1
Print #1, MyControl.Text
Close #1
End If
If TypeOf MyControl Is ComboBox Then
Open "C:\MyFile.txt" For Append As #1
For iList = 0 To MyControl.ListCount - 1
Print #1, MyControl.List(iList)
Next iList
Close #1
End If
Next
End Sub
Small mistake, thanks for correcting me Megatron :rolleyes:.
-
Try this:
Code:
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Then
'Do something
End If
Next
Hope this helps.
-
Oooh... I never get to post first. :D
-
Matthew Gates: Your line for saving the ComboBox reads For iList = 0 To Combo1.ListCount - 1; It should be For iList = 0 To MyControl.ListCount - 1
Freefly21:
Since ComboBoxes and Listboxes are the same (with respect to their list properties), you can save both of them with the same code.
Code:
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
Open "C:\MyFile.txt" For Append As #1
Print #1, ctl.Text
Close #1
End If
If (TypeOf ctl Is ComboBox) Or (TypeOf ctl Is ComboBox) Then
Open "C:\MyFile.txt" For Append As #1
For i = 0 To ctl.ListCount - 1
Print #1, ctl.List(i)
Next i
Close #1
End If
Next ctl