for next statement

  • Thread starter Thread starter David W
  • Start date Start date
D

David W

how would you use the for next statement to loop through a series of
textboxes and populate them 1 greater that the other

the series of textboxes are like [set1],[set2],[set3],etc.
the number to start with would be in the textbox [trigger]
example
me.trigger = 219993
me.set1 = 219993
me.set2 = 219994
me.set3 = 219995
and so on
 
Something like this:

Private Sub cmdFillTextBoxes_Click()
On Error GoTo ErrorPoint

Dim intI As Integer
Dim intBoxes As Integer
Dim lngValue As Long

' However many set fields you have
intBoxes = 4

If Len(Nz(Me!Trigger, "")) = 0 Then
' Trigger field is empty, inform the user
MsgBox "Please enter a value in the Trigger field " _
& "before continuing.", vbExclamation, "Missing Information"
' Move the focus to the Trigger field as a visual cue
Me.Trigger.SetFocus
Else
' Trigger value entered so remember it for later
lngValue = Me.Trigger
' Create a loop for the number of Set boxes
For intI = 1 To intBoxes
' Stuff the value into the specific Set field
Me("Set" & intI).Value = lngValue
' Increment the number by 1
lngValue = lngValue + 1
' Continue with next loop until all Set fields are filled
Next intI
End If

ExitPoint:
Exit Sub

ErrorPoint:
' Unexpected Error
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub
 
Back
Top