Delete a record if a certain field matches criteria

martlewis

Registered User.
Local time
Today, 08:22
Joined
May 3, 2011
Messages
20
Anyone know how I can make access delete a record if i select a certain value from a dropdown list.

I have a database which upon opening a new record automatically populates certain fields with default data. The problem is that if I decide I want to go back to the previous record without making any changes to the new record I get an error as my first field is linked to another table and if it's empty access says it can;'t find a matching key in the other table.

What I want is when I click the previous record button or close the form, to check the first field and if it's value equals a specific word then simply forget the record, if that makes any sense?

thanks.
 
A better solution is to cancel the update on the current record if you move away before it is complete.

Use the BeforeUpdate event of the Form. Perform the test and include Cancel = True if the test returns true.
 
Got as far as this but still get the error that the access database cannot find a matching record in the other table.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.customer = Null Then
Cancel = True
End If
End Sub
 
Try:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.customer) Then
Cancel = True
End If
End Sub

JR
 
Thats got rid ofthe error message i was getting but now i'm stuck on the new record and when i try to move to the previous record nothing happens.
 
If you want to erase the incomplete record then put this after Cancel = True.

Me.Undo

JR
 

Users who are viewing this thread

Back
Top Bottom