I am trying to get a button to close a Form and at the same time delete records on a table where certain fields are empty. I have this on the Form:
Private Sub cmdClose_Click() Dim sql As String sql = "DELETE *" _ & " FROM [AlimentoporTanque]" _ & " WHERE IsNull(Tanques) OR IsEmpty(Tanques) OR Tanques = "" OR Tanques = 0" _ & " OR IsNull(Alimento) OR IsEmpty(Alimento) OR Alimento = "" OR Alimento = 0" CurrentDb.Execute sql DoCmd.Close , "" End Sub
AlimentoporTanque is the Table’s name and Tanques and Alimento the fields that should not be empty. When I click on the button I get following MsbBox popping up:
What am I doing wrong? How do I get this running? Thanks in advance.
Advertisement
Answer
I got it working. This is the working code:
Private Sub cmdClose_Click() Dim sql As String sql = "DELETE *" _ & " FROM [AlimentoporTanque]" _ & " WHERE Tanques is Null" _ & " OR Alimento is Null" CurrentDb.Execute (sql) DoCmd.Close , "" End Sub