shorter method than elseif

T

tina

Hi
I have a form where user will select a variable number of safety hazards by
picture for each record the picture will have a path name which needs to go
into a textbox on form. there can be upto 10 pictures per record choosen from
20 or more pictures
i have started to write an else if statement but it is very long winded as
can see below which runs on click of button the check box picures text are
all in subform to mainform
I thought about using array or tab control but not sure how to do this

Thank you
Tina
Private Sub Command24_Click()
If Me.Check3 = True Then
If IsNull(Forms!nexusb1.SafetyHazard1) Then
Forms!nexusb1.SafetyHazard1 = Me.Text25
ElseIf IsNull(Forms!nexusb1.SafetyHazard2) Then
Forms!nexusb1.SafetyHazard2 = Me.Text25
ElseIf IsNull(Forms!nexusb1.SafetyHazard3) Then
Forms!nexusb1.SafetyHazard3 = Me.Text25
ElseIf IsNull(Forms!nexusb1.SafetyHazard4) Then
Forms!nexusb1.SafetyHazard4 = Me.Text25
End If
End If
If Me.Check12 = True Then
If IsNull(Forms!nexusb1.SafetyHazard1) Then
Forms!nexusb1.SafetyHazard1 = Me.Text34
ElseIf IsNull(Forms!nexusb1.SafetyHazard2) Then
Forms!nexusb1.SafetyHazard2 = Me.Text34
ElseIf IsNull(Forms!nexusb1.SafetyHazard3) Then
Forms!nexusb1.SafetyHazard3 = Me.Text34
ElseIf IsNull(Forms!nexusb1.SafetyHazard4) Then
Forms!nexusb1.SafetyHazard4 = Me.Text34
End If
End If
If Me.Check7 = True Then
If IsNull(Forms!nexusb1.SafetyHazard1) Then
Forms!nexusb1.SafetyHazard1 = Me.Text29
ElseIf IsNull(Forms!nexusb1.SafetyHazard2) Then
Forms!nexusb1.SafetyHazard2 = Me.Text29
ElseIf IsNull(Forms!nexusb1.SafetyHazard3) Then
Forms!nexusb1.SafetyHazard3 = Me.Text29
ElseIf IsNull(Forms!nexusb1.SafetyHazard4) Then
Forms!nexusb1.SafetyHazard4 = Me.Text29
End If
End If
 
D

Douglas J. Steele

Private Sub Command24_Click()

Dim intLoop As Integer
dim strCtl As String

If Me.Check3 = True Then
For intLoop = 1 To 4
strCtl = "SafetyHazard" & intLoop
If IsNull(Forms!nexusb1.Controls(strCtl)) Then
Forms!nexusb1.Controls(strCtl) = Me.Text25
Exit For
End If
Next intLoop
End If

If Me.Check12 = True Then
For intLoop = 1 To 4
strCtl = "SafetyHazard" & intLoop
If IsNull(Forms!nexusb1.Controls(strCtl)) Then
Forms!nexusb1.Controls(strCtl) = Me.Text34
Exit For
End If
Next intLoop
End If

If Me.Check7 = True Then
For intLoop = 1 To 4
strCtl = "SafetyHazard" & intLoop
If IsNull(Forms!nexusb1.Controls(strCtl)) Then
Forms!nexusb1.Controls(strCtl) = Me.Text29
Exit For
End If
Next intLoop
End If

End Sub

I'll ignore the fact that your design appears to have repeating groups in
it, which is normally a sign of improper normalization. However, have you
considered using more meaning names for your controls?
 

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