Solved Field iteration

extraordin

New member
Local time
Today, 12:27
Joined
Jun 6, 2020
Messages
2
The following code works but I am looking for a way to loop through each field. How can this be done?
Dim fname As String
Dim dname As Field
txtStartDate.SetFocus
fname = txtStartDate.Text
'For i = 1 To 4
' dname = "txtDate" & i
' dname.SetFocus
' dname.Text = DateAdd("d", i - 1, fname)
'Next
txtDate1.SetFocus
txtDate1.Text = DateAdd("d", 0, fname)
txtDate2.SetFocus
txtDate2.Text = DateAdd("d", 1, fname)
txtDate3.SetFocus
txtDate3.Text = DateAdd("d", 2, fname)
txtDate4.SetFocus
txtDate4.Text = DateAdd("d", 3, fname)
 
Code:
For i = 1 To 4
me("txtDate" & i) = DateAdd("d", i - 1, me("txtDate" & i).ControlSource)
Next
 
Shouldn't that be
Code:
For i = 1 To 4
me("txtDate" & i) = DateAdd("d", i - 1, fname)
Next

as the user is using txtStartDate to base the calculations on?
 

Users who are viewing this thread

Back
Top Bottom