Re: Data Entry Via Userform
Hi,
You can loop round the controls on your form using a construct such as:
Where in this case Characteristic_Entry is the name of the form and Control is declared as a Control.
You can then identify which controls you are interested in by for example giving them each a root name followed by an extention to differentiate them (it's a shame you can't have control arrays).
So in your code you would do something like this:
For Each Control In Characteristic_Entry.Controls
'*
'* See if this name exists in the values from the spread sheet.
'*
If Left(Control.Name, 4) <> "Titl" And Mid(Control.Name, 5, 1) = "0" Then
So here, I am looking at the control name and only processing it if does not start with the string 'Titl' and has a zero for the 5th character.
You might name your controls something like Chksafeacts_05 and chkreactions_06.
Looking for the first three characters of the control being 'chk' (translate them all to upper case in the code if you want) and the 3rd from last character being '_', if you take the value at the end of the name, this gives you the offset into your spreadsheet to place the values.
You could also build a look up table in the code to do the same thing but this is easier and when a new check box is added to the form no code changes need to take place for the existing code to handle it.
Your code would then look something like this:
For Each Control In Characteristic_Entry.Controls
'*
If Ucase(Left(Control.Name, 3)) = "CHK" And Left(Mid(Control.Name,Len(Control.Name)-3,1) = "_" Then
NextRow.Offset(0, Val(Right(Control.Name,2))).Value = "P"
End If
Next Control
Regards
Rich