Hi Forum -
I have a module that saves a worksheet to an Access database. That part is working. Now I would like to add a couple of controls into the module to check for correct values. There is one field "Request Status" that is updated by the user as well as a "Last Modified Date" field that is also updated by the user. I would like to insert a check that exits the module and displays a message box if the Request Status field is anything other than "Not Started" and there is no date in the Last Modified Date field.
I have come up with the following code which seems to perform the loop well. The problem I am encountering is getting the module to exit if the conditions are met. If I add an Exit Sub statement after the last IF statement, the code seems to always exit the sub even if the conditions are not met.
Any help someone could provide is much appreciated!
I have a module that saves a worksheet to an Access database. That part is working. Now I would like to add a couple of controls into the module to check for correct values. There is one field "Request Status" that is updated by the user as well as a "Last Modified Date" field that is also updated by the user. I would like to insert a check that exits the module and displays a message box if the Request Status field is anything other than "Not Started" and there is no date in the Last Modified Date field.
I have come up with the following code which seems to perform the loop well. The problem I am encountering is getting the module to exit if the conditions are met. If I add an Exit Sub statement after the last IF statement, the code seems to always exit the sub even if the conditions are not met.
Any help someone could provide is much appreciated!
Code:
Dim lastrow As Long
lastrow = ws.Range("B" & Rows.Count).End(xlUp).Row
With ws
For i = 2 To lastrow
If Len(Trim(.Range("A" & i).Value)) <> 0 Then _
If Range("P" & i).Value <> "Not Started" Then _
If Len(Trim(.Range("O" & i).Value)) = 0 Then _
MsgBox "The save has been cancelled. Please ensure all requests labeled as ""In Progress"" or ""Completed"" have a valid Last Modified Date filled in.", vbCritical, "Error"
Next i
End With