I've created a form and used the wizard to create a delete button. Upon testing, I noticed that the warning message would be very confusing for some users. How can I create a custom, user friendly warning message that comes up once the button is pressed?
Custom delete messages
Collapse
X
-
Tags: None
-
One way is to change the created code behind the button into:
This will show the message with a Yes/No popup and when Yes is clicked the row with the ID from the form is deleted "silently".Code:IF msgbox("Sure you want to delete this record?",vbYesNo) = vbYes then currentdb.execute ("delete * from tblX where ID=" & Me.ID end if
Just change the tblX and ID into the table and the PrimaryKey fieldname.
Nic;o) -
Ok, I went to insert the code for the delete button and found this:
How do I insert the code for the custom deleter prompt without breaking anything?Code:Private Sub delete_indep_Click() On Error GoTo Err_delete_indep_Click DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 Exit_delete_indep_Click: Exit Sub Err_delete_indep_Click: MsgBox Err.Description Resume Exit_delete_indep_Click End SubComment
-
I tried the code with your suggestions and got a syntax error. Here is what I did:
What did I do wrong?Code:Private Sub delete_indep_Click() On Error GoTo Err_delete_indep_Click If MsgBox("Sure you want to delete this record?", vbYesNo) = vbYes Then Me.Requery currentdb.execute ("delete *from Project_Contact_Record where Contact_ID=" & Me.ID End If Exit_delete_indep_Click: Exit Sub Err_delete_indep_Click: MsgBox Err.Description Resume Exit_delete_indep_Click End SubComment
-
Try :
Please try to include the line number where an error occurrs when reporting a problem in future.Code:Private Sub delete_indep_Click() On Error GoTo Err_delete_indep_Click If MsgBox("Sure you want to delete this record?", vbYesNo) = vbYes Then currentdb.execute ("delete * from Project_Contact_Record where Contact_ID=" & Me.ID Me.Requery End If Exit_delete_indep_Click: Exit Sub Err_delete_indep_Click: MsgBox Err.Description Resume Exit_delete_indep_Click End SubComment
-
I think it needs a "Call" if it has the parentheses. The following are both usable syntax :I usually use the latter to express explicitly that, if it is a function, I'm dropping the returned value anyway. In this case that particular line (in my preferred format) would be :Code:CurrentDB.Execute StringVal Call CurrentDB.Execute(StringVal)
Code:Call CurrentDB.Execute("DELETE * FROM [Project_Contact_Record] WHERE [Contact_ID]=" & Me.ID)Comment
-
I tried the code again with the changes and got "Compile error: Method or data not found." The cursor stands on line 5.
Here's the code I used.
Code:Private Sub delete_indep_Click() On Error GoTo Err_delete_indep_Click If MsgBox("Sure you want to delete this record?", vbYesNo) = vbYes Then CurrentDb.Execute ("delete * from Project_Contact_Record where Contact_ID=" & Me.ID) Me.Requery End If Exit_delete_indep_Click: Exit Sub Err_delete_indep_Click: MsgBox Err.Description Resume Exit_delete_indep_Click End SubComment
-
Originally posted by ThirdworldI tried the code again with the changes and got "Compile error: Method or data not found." The cursor stands on line 5.
Here's the code I used.
Code:Private Sub delete_indep_Click() On Error GoTo Err_delete_indep_Click If MsgBox("Sure you want to delete this record?", vbYesNo) = vbYes Then CurrentDb.Execute ("delete * from Project_Contact_Record where Contact_ID=" & Me.ID) Me.Requery End If Exit_delete_indep_Click: Exit Sub Err_delete_indep_Click: MsgBox Err.Description Resume Exit_delete_indep_Click End Sub
I have just gotten the correct syntax (after too long of troubleshooting !).
Line 5 should be (all on one line):
If the table Project_Contact _Record is actually three seperate words, it needs to be enclosed in square brackets. ie. [Project Contact Record].Code:CurrentDb.Execute "DELETE * FROM Project_Contact_Record WHERE Contact_ID = '" & Me!ID & "'"
I hope this works for you :)Comment
-
-
You'd better post what you've changed your code to I suggest.Originally posted by ThirdworldI still got the error. :(
@Blakerrr
You would have saved yourself some time if you'd read my last post #11, which actually gives the correct syntax. Your version is also correct (syntactically) , but you added quotes (') around Me.ID which (from what we've seen so far) is a numeric value and therefore doesn't require them.Comment
Comment