From: tina on 3 Jun 2010 07:04 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
From: Douglas J. Steele on 3 Jun 2010 08:05 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? -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele Co-author: Access 2010 Solutions, published by Wiley (no e-mails, please!) "tina" <tina(a)discussions.microsoft.com> wrote in message news:DCA1F3F7-BF18-4261-8529-7E99791F7AAD(a)microsoft.com... > 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 >
|
Pages: 1 Prev: Delete code competing with BeforeUpdate validation Next: Testing numeric input |