Help with "For...Next" and variables

  • Thread starter Thread starter Azza
  • Start date Start date
A

Azza

'===================================================================
'Checks if the complee date fied has been completed
'===================================================================
Dim vDateComplete1 As Long
vDateComplete1 = 0
If cboxDay1 <> "" Then
vDateComplete1 = vDateComplete1 + 1
End If
If cboxMonth1 <> "" Then
vDateComplete1 = vDateComplete1 + 1
End If
If cboxYear1 <> "" Then
vDateComplete1 = vDateComplete1 + 1
End If
If vDateComplete1 = 1 Or vDateComplete1 = 2 Then
MsgBox "Please complete the date field"
cboxDay1.SetFocus
Exit Sub
End If

Dim vDateComplete2 As Long
vDateComplete2 = 0
If cboxDay2 <> "" Then
vDateComplete2 = vDateComplete2 + 1
End If
If cboxMonth2 <> "" Then
vDateComplete2 = vDateComplete2 + 1
End If
If cboxYear2 <> "" Then
vDateComplete2 = vDateComplete2 + 1
End If
If vDateComplete2 = 1 Or vDateComplete2 = 2 Then
MsgBox "Please complete the date field"
cboxDay2.SetFocus
Exit Sub
End If
...... (15 times)

How do I variablise this using "For...Next"???

It checks 15 sets of 3 date boxes to make sure each is complete or
totally empty - it works, but I would like to condense the code ..

Problem: I do not know how to code cboxMonth(i) .. cboxYear(i) ...
etc, to cycle through 1-15??

Please help
 
"Azza" <[email protected]> schreef in bericht
.....
How do I variablise this using "For...Next"???

It checks 15 sets of 3 date boxes to make sure each is complete or
totally empty - it works, but I would like to condense the code ..

Problem: I do not know how to code cboxMonth(i) .. cboxYear(i) ...
etc, to cycle through 1-15??

Please help

Use a Form or Worksheet object, and then walk through the Controls
collections using For...Each...Next

Dim uForm As userFrm
Dim frmCtrls As Controls
Dim frmCtrl As Control
Set uForm = New userFrm
Set frmCtrls = uForm.Controls
For Each frmCtrl In frmCtrls
MsgBox frmCtrl.Name
Next
 
Back
Top