Hello -
I am trying to loop 17 textboxes after a user needs to edit the record and update the Due Date in txtDueDate1. The screen shot below shows some textboxes in grey because they are default values when the userform is launched. I read many threads and watch videos on looping through textboxes but I can't get the code below to work and must be missing something simple. When a user selects a record from the Listbox to edit and changes the Due Date in txtDueDate1 then when clicking the Update Due Dates button, I want to subsequent dates to get updated based on Calendar or Business Days. I am coming across two (2) errors.
1) A mismatch error where the TDD value is blank
2) The Business Days (WorksheetFunction.WorkDay) is not working and message says argument not optional so I don't know how to solve it.
Below is the code and I hope anyone can help.
Private Sub CommandButton1_Click()
Dim i As Integer
Dim TDD
Dim txtDays
Dim txtBusCal
For i = 2 To 17
Controls("txtDueDate" & i).Value = "<>"
If Controls("txtBusCal" & i).Value = "Calendar" Then
TDD.Value = CDate(Controls("txtDueDate" & i - 1).Value) + (Controls("txtDays" & i).Value)
TDD.Value = Format(CDate(TDD.Value))
Else
If Controls("txtBusCal" & i).Value = "Business" Then
TDD.Value = WorksheetFunction.WorkDay(CDate(Controls("txtDueDate" & i - 1).Value)) + (Controls("txtDays" & i).Value)
TDD.Value = Format(CDate(TDD.Value))
End If
End If
Next i
End Sub
I am trying to loop 17 textboxes after a user needs to edit the record and update the Due Date in txtDueDate1. The screen shot below shows some textboxes in grey because they are default values when the userform is launched. I read many threads and watch videos on looping through textboxes but I can't get the code below to work and must be missing something simple. When a user selects a record from the Listbox to edit and changes the Due Date in txtDueDate1 then when clicking the Update Due Dates button, I want to subsequent dates to get updated based on Calendar or Business Days. I am coming across two (2) errors.
1) A mismatch error where the TDD value is blank
2) The Business Days (WorksheetFunction.WorkDay) is not working and message says argument not optional so I don't know how to solve it.
Below is the code and I hope anyone can help.
Private Sub CommandButton1_Click()
Dim i As Integer
Dim TDD
Dim txtDays
Dim txtBusCal
For i = 2 To 17
Controls("txtDueDate" & i).Value = "<>"
If Controls("txtBusCal" & i).Value = "Calendar" Then
TDD.Value = CDate(Controls("txtDueDate" & i - 1).Value) + (Controls("txtDays" & i).Value)
TDD.Value = Format(CDate(TDD.Value))
Else
If Controls("txtBusCal" & i).Value = "Business" Then
TDD.Value = WorksheetFunction.WorkDay(CDate(Controls("txtDueDate" & i - 1).Value)) + (Controls("txtDays" & i).Value)
TDD.Value = Format(CDate(TDD.Value))
End If
End If
Next i
End Sub