On Delete Prompts Twice (1 Viewer)

jcruzAME

Registered User.
Local time
Yesterday, 19:01
Joined
Oct 5, 2011
Messages
135
On a subform, I have deletions enabled and a prompt if they try to delete an entry that asks if they are sure they want to delete it.

The code works, but it will pop up twice when asking.

Answer = MsgBox("Are you sure you want to delete this Asset History entry?", vbYesNo + vbQuestion, "Delete Entry")
If Answer = vbNo Then Cancel = True
Exit Sub

The code is as above, but it will run twice each time you say no. As in, it pops up, you click no, then it pops up again, and if you click no it goes away and doesn't delete.

Any info on why this happens twice even though I have the Exit Sub in there?
 

RainLover

VIP From a land downunder
Local time
Today, 10:01
Joined
Jan 5, 2009
Messages
5,041
Is the message exactly the same or is it slightly different?

If the same then please post the full code and we will have a look.
 

jcruzAME

Registered User.
Local time
Yesterday, 19:01
Joined
Oct 5, 2011
Messages
135
Yeah, it's the same prompt twice, as if it is running twice. On another form that is a datasheet view, it has the same code and only runs once.

EDIT: I should also note that if you click yes on the prompt, it will delete the entry and not pop up again.
 

jcruzAME

Registered User.
Local time
Yesterday, 19:01
Joined
Oct 5, 2011
Messages
135
That is the only code I have for the On Delete event on that subform.
 

RainLover

VIP From a land downunder
Local time
Today, 10:01
Joined
Jan 5, 2009
Messages
5,041
Code:
Answer = MsgBox("Are you sure you want to delete this Asset History entry?", vbYesNo + vbQuestion, "Delete Entry")
  If Answer = vbNo Then Cancel = True
  Exit Sub

This will error. It is incomplete.

That is all I call tell you at the moment.
 

jcruzAME

Registered User.
Local time
Yesterday, 19:01
Joined
Oct 5, 2011
Messages
135
Can you expand on why? It currently works besides the double prompt. If they click yes, it deletes the entry and carries on. If you click no, it is prompting twice. There are no other errors with this code.
 

RainLover

VIP From a land downunder
Local time
Today, 10:01
Joined
Jan 5, 2009
Messages
5,041
For a start it must have a name like

Private Sub On_Click ()

Also some code that actually does the deletion.

Your complete code is part of a message box. This will not do what you want so I am at a loss as to what is going on.
 

jcruzAME

Registered User.
Local time
Yesterday, 19:01
Joined
Oct 5, 2011
Messages
135
Private Sub Form_Delete(Cancel As Integer)
Dim Answer As Integer
Answer = MsgBox("Are you sure you want to delete this Asset History entry?", vbYesNo + vbQuestion, "Delete Entry")
If Answer = vbNo Then Cancel = True
Exit Sub
End Sub

It is in the On Delete event. It is prompted by highlighting an entry with the record selector, and hitting the delete key. I wasn't sure what you meant by the rest of the code. There is no coded needed for the deletion as when you click yes it goes through with deleting the actual entry.
 

RainLover

VIP From a land downunder
Local time
Today, 10:01
Joined
Jan 5, 2009
Messages
5,041
In your Access Options you have set it to Confirm Deletions.

You need to fix that by unchecking the box.

If you can't find it I can tell you in Access 2003 but not 2007 or 2010. You will need to use access help.

I would have thought "If the same then please post the full code and we will have a look. " fairly simple. I will try to come up with something better next time.
 

jcruzAME

Registered User.
Local time
Yesterday, 19:01
Joined
Oct 5, 2011
Messages
135
Well I thought you had taken that as I was only posting an excerpt, not the code inside the event. Thank you for the information.
 

RainLover

VIP From a land downunder
Local time
Today, 10:01
Joined
Jan 5, 2009
Messages
5,041
By seeing the full code I was able to establish that it was your Options causing the problem not the code.

It helps to have full disclosure in order to reach a proper conclusion.

Guess work does not work.
 

boblarson

Smeghead
Local time
Yesterday, 17:01
Joined
Jan 12, 2001
Messages
32,059
Why do you have the Exit Sub in there anyway, if that is your entire code. There is nothing else to run. Plus, if you want to make sure that something is part of the If...Then...Else statement you need to use more than one line. The line:

If Answer = vbNo Then Cancel = True

is self-contained and the Exit Sub you have would fire even if the answer is yes. In this case it doesn't matter because it is extraneous but it can in other situations. So, what you would normally do is writ it like this:
Code:
If Answer = vbNo Then 
       Cancel = True
       Exit Sub
End If
 

jcruzAME

Registered User.
Local time
Yesterday, 19:01
Joined
Oct 5, 2011
Messages
135
Thank you for pointing that out. I can't believe I didn't pick that up. I could've sworn I changed it to the correct formatting at some point but I guess I didn't.

Thanks again.
 

Users who are viewing this thread

Top Bottom