Below I have some code, that I use to delete all information in a table:
This code deletes all data in the table. I would like to have it tweaked a little bit, so it only deletes the data from the table, where the field "ReportDate" is between the specified dates in the text boxes "txtDate1" & "txtDate2".
I see four scenarios:
1. Both txtDate1 and txtDate2 has been updated. In this case all data between those two dates should be deleted.
2. None of the two text boxes has been updated. In this case all data should be deleted.
3. Only txtDate1 is updated, and txtDate2 is left blank. In this case all data after txtDate1 should be deleted.
4. Only txtDate2 is updated, and txtDate1 s left blank. In this case all data before txtDate2 should be deleted.
All assistance is highly appreciated.
/Anders
Code:
Private Sub cmdDeleteAllData_Click()
Dim answer As String
Dim answer2 As String
Dim answer3 As String
Dim strSQL1 As String
answer = MsgBox("Are you sure you want to delete all data?.", vbYesNo)
If answer = 6 Then
answer2 = MsgBox("Are you absolutely sure? You can not undo the this!!!", vbYesNo)
If answer2 = 6 Then
strSQL1 = "DELETE * FROM qryReport"
CurrentProject.Connection.Execute strSQL1
answer3 = MsgBox("All data has been erased!", vbOKOnly)
Else
Exit Sub
End If
Else
Exit Sub
End If
End Sub
This code deletes all data in the table. I would like to have it tweaked a little bit, so it only deletes the data from the table, where the field "ReportDate" is between the specified dates in the text boxes "txtDate1" & "txtDate2".
I see four scenarios:
1. Both txtDate1 and txtDate2 has been updated. In this case all data between those two dates should be deleted.
2. None of the two text boxes has been updated. In this case all data should be deleted.
3. Only txtDate1 is updated, and txtDate2 is left blank. In this case all data after txtDate1 should be deleted.
4. Only txtDate2 is updated, and txtDate1 s left blank. In this case all data before txtDate2 should be deleted.
All assistance is highly appreciated.
/Anders