Do Loop or DoWhile question

L

Lloyd Couture

It seems so I should be able to use a Do Loop or Do while for this code but
I can't seem to grasp how to implement it.

I have a form with 32 text boxes, each box has two check boxes and one text
box. I have to put the following code in the after update of the check boxes
and in the oncurrent of the form.

For MeCompleted

Private Sub Form_Current()
If Me!IsCompleted = True Then
DateToDue.ControlSource = "CompletionDate"
Label19.Caption = "Completion Date"
ElseIf Me!Follow1 = True Then
DateToDue.ControlSource = "FollowUpDate"
Label19.Caption = "Date To Due"
Else
Label19.Caption = "Date to Due"
DateToDue.ControlSource = DateToDue.DefaultValue

End If

For MeCompleted 2

If Me!IsCompleted2 = True Then
DateToDue2.ControlSource = "CompletionDate2"
Label37.Caption = "Completion Date"
ElseIf Me!Follow2 = True Then
DateToDue2.ControlSource = "FollowUpDate2"
Label37.Caption = "Date To Due"
Else
Label37.Caption = "Date to Due"
DateToDue2.ControlSource = DateToDue2.DefaultValue

End If

The code is the same for all 32 controls, the only change is the control
names which are numbered sequentially.
Any suggestions would be appreciated.
 
A

Andrew Smith

You'll need to rename some of the controls, but something like this should
work:

Dim i as integer
Dim strSource as string
Dim strCaption as string

for i = 1 to 32
if me("iscompleted" & i) then
strSource = "CompletionDate"
strCaption = "Completion Date"
elseif me.("follow" & i) then
strSource = "FollowUpDate"
strCaption = "Date To Due"
else
strSource = (I don't understand what you're trying to do with this
one!)
strCaption = "Date To Due"
end if
me("DateToDue" & i).ControlSource = strSource
me("Label" & i).Caption = strCaption
next

It looks like you should really normalise your database though!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top