View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Cycling through variables.

This might help get you started

'-----------------------------------------------------------------
Private Sub SetComboboxes()
'-----------------------------------------------------------------
Dim ctl As msforms.Control

For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.AddItem 1
ctl.AddItem 2
End If
Next ctl

End Sub


--

HTH

RP

"Azza" wrote in message
m...
I have this code:

'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 < (0 Or 3) Then
MsgBox "Please complete the date field"
cboxDay1.SetFocus
End If

and three combo boxes for day, month and year.

The problem is I have 15 of these date fields to check and although I
know how to cycle though a spreadsheet (For Rownumber = 1 to ....), I
do not know how
to cycle through fields in a form.
i.e. I have cboxDay1, cboxDay2 .... and I do not know how to
varibalise it ??

I was given the code With Me.Controls("ComboBox" & i) to fill the
boxes but unsure what the "Controls" part of the code does and if to
use it for the next part of the code.

Please help - my spreadsheet is looking so jammy with loads and loads
of uneccessary code.

cheers
Aaron