extraordinare
Member
I have searched the VB.NET Forums for references towards control arrays in Access 2003 using VBA code. I haven't found what I was looking for. I will try to explain. I am trying to find a way to programmatically loop through a collection of controls on a form. Here is an example of code that I have written so far.
The problem is the For Loop. I can loop through multiple controls but cannot access the Textbox control properties. Like the Name property of the Textbox. If someone has a creative way for achieving this please let me know because it will take to much to write each control individually.
VB.NET:
Option Compare Database
Option Explicit
Private Sub btnSave_Click()
Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim strMonth, strYear, strMonthID, strQuery As String
Dim ctrl As Control
'Checks if the Month field is selected
If cboMonth.ListIndex = -1 Then
MsgBox "Please select a Month ", vbOKOnly
cboMonth.SetFocus
Exit Sub
End If
'Checks if the Year field is selected
If cboYear.ListIndex = -1 Then
MsgBox "Please select a Year ", vbOKOnly
cboYear.SetFocus
Exit Sub
End If
strMonth = CStr(IIf(cboMonth.ListIndex < 10, 0 & cboMonth.ListIndex, cboMonth.ListIndex))
strYear = CStr(cboYear.Value)
'Combines the Month and Year into one variable
strMonthID = strMonth & strYear
'Checks each TextBox to determine whether or not it meets certain criteria
'will exit the subroutine if any conditions test true
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
MsgBox "Cool "
End If
Next ctrl
Set cnn = New ADODB.Connection
Set cnn = CurrentProject.Connection
End Sub
The problem is the For Loop. I can loop through multiple controls but cannot access the Textbox control properties. Like the Name property of the Textbox. If someone has a creative way for achieving this please let me know because it will take to much to write each control individually.